SimpleDateFormat与DateTime常用日期转换

原创
2017/08/22 15:30
阅读数 308

SimpleDateFormat:

		String dateString = "2017-03-05T16:00:00.000Z"; 
		dateString = dateString.replace("Z", " UTC");
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
		Date d = format.parse(dateString);
		System.out.println("1."+d.getTime());

		SimpleDateFormat sdf =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long date = sdf.parse("2017-04-11 19:35:00").getTime();
		
		System.out.println("2."+date);
		System.out.println("3."+sdf.format(new Date(date)));
		System.out.println("4."+sdf.format(new Date()));		
		System.out.println("5."+sdf.format(new Date(Long.parseLong("1477929600000"))));//2016-09-25 18:41:32,2016-10-24 18:41:32		
		System.out.println("6."+String.format("%010d",1488181707000L/1000));

1.1488729600000
2.1491910500000
3.2017-04-11 19:35:00
4.2017-08-22 15:27:37
5.2016-11-01 00:00:00
6.1488181707

 

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部