public List<String> processToYYYYMMDD(String date1,String date2){
List<String> timeList=new ArrayList<String>();
if(date1.equals(date2)){
timeList.add(date1);
return timeList;
}
String tmp;
timeList.add(date1);
if(date1.compareTo(date2) > 0){//确保 date1的日期不晚于date2
tmp = date1; date1 = date2; date2 = tmp;
}
tmp = format.format(str2Date(date1).getTime() + 3600*24*1000);
timeList.add(tmp);
int num = 0;
while(tmp.compareTo(date2) < 0){
num++;
tmp = format.format(str2Date(tmp).getTime() + 3600*24*1000);
timeList.add(tmp);
}
// if(num == 0)
// System.out.println("两个日期相邻!");
return timeList;
}
private Date str2Date(String str) {
if (str == null) return null;
try {
return format.parse(str);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public String[] getAllMonths(String start, String end){
String splitSign="-";
String regex="\\d{4}"+splitSign+"(([0][1-9])|([1][012]))"; //判断YYYY-MM时间格式的正则表达式
if(!start.matches(regex) || !end.matches(regex)) return new String[0];
List<String> list=new ArrayList<String>();
if(start.compareTo(end)==0){
String[] result=new String[1];
result[0]=start;
return result;
}
if(start.compareTo(end)>0){
//start大于end日期时,互换
String temp=start;
start=end;
end=temp;
}
String temp=start; //从最小月份开始
while(temp.compareTo(start)>=0 && temp.compareTo(end)<=0){
list.add(temp); //首先加上最小月份,接着计算下一个月份
String[] arr=temp.split(splitSign);
int year=Integer.valueOf(arr[0]);
int month=Integer.valueOf(arr[1])+1;
if(month>12){
month=1;
year++;
}
if(month<10){//补0操作
temp=year+splitSign+"0"+month;
}else{
temp=year+splitSign+month;
}
}
int size=list.size();
String[] result=new String[size];
for(int i=0;i<size;i++){
result[i]=list.get(i);
}
return result;
}
分享到:
相关推荐
onclick="SelectDate(this)" 年月日,默认格式yyyy-MM-dd onclick="SelectDate(this,'yyyy 年')" 年份 onclick="SelectDate(this,'yyyy 年 MM 月')" 年月 onclick="SelectDate(this,'yyyy\-MM\-dd')" 年月日 onclick...
1、合法的日期:MSDN上规定–在公元(基督纪元)0001 年 1 月 1 日午夜 12:00:00 到公元 (C.E.) 9999 年 12 月 31 日晚上 11:59:59 之间的日期和时间 查看http://msdn.microsoft.com/zh-cn/library/system.datetime...
js获取当前时间yyyymmddhhmmss
java计算两个时间(yyyy-MM-dd HH:mm:ss)相差月数两个时间格式可为年月日时分秒
<ASP:BOUNDCOLUMN DATAFIELD= "JoinTime " DATAFORMATSTRING= "{0:yyyy-MM-dd} " > <ITEMSTYLE WIDTH= "18% " > 2.数据控件如DataGrid/DataList等的件格式化日期方法: e.Item.Cell[0].Text = Convert.ToDateTime...
input框中自动展示当前日期</title> </head> <body> <input type=text id=input> [removed] //获取input元素 var _input = document.getElementById('input'); var date = new Date();...
年月日格式可以和下面的交换 yyyyMMdd HH yyyyMMdd HHmm yyyyMMdd HH mm yyyyMMdd HH:mm yyyyMMdd HH:mm yyyyMMdd HH mm ss yyyyMMdd HH:mm:ss yyyyMMdd HH:mm:ss MM/dd MM-dd MM.dd HH HHmm HH mm HH:mm HH:mm...
public static final String FORMAT_ONE = "yyyy-MM-dd HH:mm:ss"; // 格式:年-月-日 小时:分钟 public static final String FORMAT_TWO = "yyyy-MM-dd HH:mm"; // 格式:年月日 小时分钟秒 public ...
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date parse = simpleDateFormat.parse("2019-09-08"); //字符串转日期 String format = simpleDateFormat.format(parse); //日期转...
根据生日计算年龄,只精确到日期 接受Calendar类型的日期数据,计算天数差 获取当前日期,格式化成yyyy-MM-dd...接受YYYY-MM-DD的日期字符串参数,返回两个日期相差的天数 接受Date类型的日期参数,返回两个日期相差的天数
下面小编就为大家带来一篇js获取当前年月日-YYYYmmDD格式的实现代码。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
日期格式年月日(yyyy-mm-dd) 时间格式时分(hh:mm)
javascript的TRIM函数和日期时间格式化函数 如 var d = new Date().format('yyyy-MM-dd hh:mm:ss');
日期格式包括:年(yyyy)、年月(yyyyMM、yyyy-MM)、年月日(yyyyMMdd、yyyy-MM-dd)、年月日时分(yyyyMMddHHmm、yyyy-MM-dd HH:mm)、年月日时分秒(yyyyMMddHHMISS、yyyy-MM-dd HH:MI:SS)等各种格式。...
在文本框输入日期,会有日历的格式出现,输入的日期格式为yyyy-MM-dd
利用js同时生成当日(YYYY-MM-DD)、当月(YYYY-MM)、当年(YYYY);通格式的上一日、上一月、上一年
如(yyyy+mm+dd hh:mm:ss) (yyyy/mm/dd hh-mm-ss) 除此方法.还有可以把系统当前的“年月日时分秒\"转化为整形.如asp.net+xml中.xml文档的ID号,如当前时间为2008-8-8 20:08:08可用(20080808200808)整形表式...
* 将某个日期格式字符串转换成另一指定格式日期字符串 例:传入"2009/1/15 16:58:00","yyyy/MM/dd * hh:mm:ss","yyyy年M月d日 a h时m分s秒" 则返回 “2009年1月15日 下午 4时58分0秒” * * @param dateStr ...
以上实现的是yyyy-MM-dd格式的日期验证,考虑到连字符的不同,以及月和日可能为M和d,即yyyy-M-d的格式,可以对以上正则进行扩展 ^(?:(?!0000)[0-9]{4}([-/.]?)(?:(?:0?[1-9]|1[0-2])([-/.]?)(?:0?[1-9]|1[0-9]|2[0-...
js_trim()十二种实现.txtjs_trim()十二种实现.txtjs_trim()十二种实现.txtjs_trim()十二种实现.txt