首页 » 技术 » 正文

关于时间转换的代码

时间转换的相关代码

public static long dateToLong (String in) {
// 将日期转成毫秒 yyyy-MM-dd HH:mm:ss 2014-5
SimpleDateFormat format = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);

// String systimeString =com.alipay.util.UtilDate.getDateFormatter();
java.util.Date date2;
Calendar cal = Calendar.getInstance();
try {
date2 = format.parse(in);
cal.setTime(date2);

} catch (ParseException e) {
e.printStackTrace();
}

return cal.getTimeInMillis();
}
// 将毫秒转成日期 yyyy-MM-dd HH:mm:ss 2014-5
public static String longToDate (long in) {
SimpleDateFormat format = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(in);

String dateString = format.format(calendar.getTime());
// System.out.println(“longToDate: long:”+ in +” date:”+ dateString);
return dateString;

}

 

本文共 3 个回复

  • BHW 2017/04/03 03:43

    Hello There. I found your blog using msn. This is a really well written article. I'll be sure to bookmark it and return to read more of your useful information. Thanks for the post. I'll definitely return.

  • Maymanlito.Over-Blog.com 2017/05/06 06:18

    Thanks for finally talking about >关于时间转换的代码 | SevenNinghtS <Loved it!

  • http://jumbledhitch2418.Jimdo.com/ 2017/05/09 23:15

    Right here is the perfect website for everyone who hopes to find out about this topic. You realize a whole lot its almost tough to argue with you (not that I really will need to?HaHa). You certainly put a new spin on a subject that has been discussed for many years. Wonderful stuff, just excellent!

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据