日期->字符串,字符串->日期;日期->毫秒,毫秒>日期-
private static void getDate() { // TODO Auto-generated method stub long time = System.currentTimeMillis(); Date date = new Date(time); System.out.println("毫秒转日期"+date); System.out.println("日期转毫秒"+date.getTime()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:dd:SS"); String s = dateFormat.format(date); System.out.println("日期转字符串"+s); try { System.out.println("字符串转日期"+dateFormat.parse(s)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
毫秒转换为多少天时,可以毫秒/1000/60/60/24
本文介绍了如何使用Java实现日期与毫秒之间的相互转换,并演示了如何将日期转换成字符串及从字符串中解析出日期的具体步骤。
1378

被折叠的 条评论
为什么被折叠?



