将以毫秒为单位的时期转换为日期和时间:Java [英] Converting Epoch in milliseconds into Date and Time: Java
本文介绍了将以毫秒为单位的时期转换为日期和时间:Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谢谢
解决方案
我想提取日期(02 / 11/2013)和时间(09:23 am)分开从两个字符串。
请参阅 SimpleDateFormat javadoc | SimpleDateFormat turorial 。这将帮助您解决问题。
日期date = new Date(epoch); //'epoch'in long
SimpleDateFormat formatter = new SimpleDateFormat(MM / dd / yyyy);
String dateString = formatter.format(date);
formatter = new SimpleDateFormat(hh:mm a); //a是AM / PM标记
String time = formatter.format(date);
I have an epoch value in milliseconds. I would like extract the date (02/11/2013) and time (09:23 am) from this separately in two strings.
could someone please help with that? Thanks
解决方案
"I would like extract the date (02/11/2013) and time (09:23 am) from this separately in two strings."
See SimpleDateFormat javadoc | SimpleDateFormat turorial. This will help you with your problem.
Date date = new Date(epoch); // 'epoch' in long
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
String dateString = formatter.format(date);
formatter = new SimpleDateFormat("hh:mm a"); //The "a" is the AM/PM marker
String time = formatter.format(date);
这篇关于将以毫秒为单位的时期转换为日期和时间:Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文