为什么Joda时间会将输入字符串中的PM更改为AM? [英] Why does Joda time change the PM in my input string to AM?

查看:164
本文介绍了为什么Joda时间会将输入字符串中的PM更改为AM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的输入字符串是PM时间:

My input string is a PM time:

    log(start);
    // Sunday, January 09, 2011 6:30:00 PM

使用 Joda Time的图案语法如下解析DateTime:

I'm using Joda Time's pattern syntax as follows to parse the DateTime:

    DateTimeFormatter parser1 = 
    DateTimeFormat.forPattern("EEEE, MMMM dd, yyyy H:mm:ss aa");
    DateTime startTime = parser1.parseDateTime(start);

那么,为什么我的输出字符串AM?

So, why is my output string AM?

    log(parser1.print(startTime));
    // Sunday, January 09, 2011 6:30:00 AM


推荐答案

您的解析字符串包含H,它告诉您的解析器将值解释为24小时制的小时(0..23)。所以6被解释为一天的第六个小时。在早上。打印的AM是因为解析的整体日期被认为是在早上。

Your parse string contains "H" which is telling your parser to interpret the value as a 24-hour hour of day (0..23). So the 6 is interpreted as the 6th hour of the day. In the morning. The AM that's printed is because the overall date parsed is considered to be in the morning.

如果要使用12小时的时间,请将格式字符串更改为:

If you want to use 12-hour time, change your format string to:

"EEEE, MMMM dd, yyyy h:mm:ss aa".

'h'将被解释为12小时的小时(1..12)

'h' will be interpreted as a 12-hour hour of day (1..12)

这篇关于为什么Joda时间会将输入字符串中的PM更改为AM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆