一、Mon Jul 07 17:38:50 CST 2014轉yyyy-MM-dd Hjavascript
String str="Mon Jul 07 17:38:50 CST 2014";
DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss 'CST' yyyy",Locale.US);
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf.format(df.parse(str)));java
二、將ctime以年月日的格式顯示出來:web
ctime | uint | 否 | 文件或目錄的建立時間。 |
響應示例:app
{"list":[{"fs_id":3528850315,"path":"/apps/yunform/music/hello","ctime":1331184269,"mtime":1331184269,"block_list":["59ca0efa9f5633cb0371bbc0355478d8"],"size":13,"isdir":0}], "request_id":4043312670}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
String date = sdf.format(new Date(時間戳*1000L));
System.out.println(date);ui
兩個日期比較大小:spa
String t1="2015-04-25 15:20:55";code
String t2="2016-03-31 19:55:20";orm
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");blog
Date d1 = sdf.parse(t1);ip
Date d2 = sdf.parse(t2);
if (d1.getTime()>d2.getTime()) {//1427786455000 1427802920000
System.out.println("t2在前");
}else {
System.out.println("t1在前");
}
原文地址:http://blog.163.com/zhaowenchao_vip/blog/static/17151514420114354349486/
3.日期時間相加相減:
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
String str="20110823";
Date dt=sdf.parse(str);
Calendar rightNow = Calendar.getInstance();
rightNow.setTime(dt);
rightNow.add(Calendar.YEAR,-1);//日期減1年
rightNow.add(Calendar.MONTH,3);//日期加3個月
rightNow.add(Calendar.DAY_OF_YEAR,10);//日期加10天
rightNow.add(Calendar.MONTH, 5); //當前月份+5
rightNow.add(Calendar.MINUTE, 5); //當前分鐘+5
Date dt1=rightNow.getTime();
System.out.println(format.format(dt1));
四、long型的毫秒轉HH:mm:ss
方法一:
long long2=300 * 1000-TimeZone.getDefault().getRawOffset();//減去時區差8個小時
SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");
方法二:sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String format = sdf.format(long2);