java 以 24 小时格式获取时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17539731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 02:15:51  来源:igfitidea点击:

Getting the time in 24 hour format

javadatetime

提问by Ruchira Gayan Ranaweera

I have to print the date in 24 hour format rite now as shown below the date is printed in 12 hr format i want it to be get printed in 24 hour format as the file will be containg UK timestamp

我现在必须以 24 小时格式打印日期,如下所示日期以 12 小时格式打印我希望它以 24 小时格式打印,因为文件将包含英国时间戳

String currDate = new SimpleDateFormat("MM-dd-yyyy-HH-mm").format(new Date());
System.out.println("ABC_0101-"+currDate);
ABC_0101-07-09-2013-11-16

Please advise as shown above the file name is ABC_0101 followd by a seprator "-" and then the time stamp 07-09-2013-11-16 , please advise how the time particulary will be printed in 24 hour format

请告知如上所示文件名是 ABC_0101 后跟分隔符“-”,然后是时间戳 07-09-2013-11-16 ,请告知如何以 24 小时格式打印特别的时间

回答by Subhrajyoti Majumder

you could use HHor KKto format hour in 24.

您可以使用HHKK将小时格式化为 24。

H Hour in day (0-23)
k Hour in day (1-24)

H 小时 (0-23)
k 小时 (1-24)

format you can use MM-dd-yyyy-kk-mmor MM-dd-yyyy-HH-mm.

您可以使用的格式MM-dd-yyyy-kk-mmMM-dd-yyyy-HH-mm.

回答by Ruchira Gayan Ranaweera

Currently what have you done is working. and that will give you time in 24 hour format. change your system time to some where in afternoon and check it.

目前你所做的是工作。这将为您提供 24 小时格式的时间。将您的系统时间更改为下午的某个时间并检查它。

    String currDate = new SimpleDateFormat("MM-dd-yyyy-HH-mm").format(new Date());
    System.out.println(currDate);

回答by Richard Fung

I'm confused. It looks like your code will print in 24 hour format to me? It says here that HH represents the 24 hour format

我糊涂了。看起来您的代码将以 24 小时格式打印给我?这里说HH代表24小时制

http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

回答by Evgeniy Dorofeev

HH is exactly what you need. It's 24 hour format. See SimpleDateFormat API. Change your computer time to 16:00 and try your code again to test.

HH 正是您所需要的。这是 24 小时制。请参阅 SimpleDateFormat API。将您的计算机时间更改为 16:00 并再次尝试您的代码以进行测试。