如何在12HR中解决分钟精度格式化丢失的问题? [英] How to resolve loss of minute precision formatting a moment in 12HR?
问题描述
我已经将ISO日期字符串转换为片刻,然后使用 .format(MM / DD / YYYY HH:MM)
格式化该片段。
当输出最终格式化的时刻时,分钟值与最初从iso字符串中读取的值不正确。
在这种情况下,ISO字符串值保存为3:10 PM或2016-08-03T03:10:00.000Z,如字符串中所示。 但是当我调用格式的时候,这个值是4:07 PM,这意味着在格式化过程中已经减去了三分钟。
在调试过程中,我在每个分配阶段注意到以下值:
$ b
第1步(将db值转换为ISO字符串):
var actualBCR_Local = moment.utc('@ Model.Escalation.Actual_BCR_ISO')。toISOString();
value:2016-08-03T03:10:00.000Z
第2步(将ISO字符串转换为momentjs时刻,以表示当地时间GMT + 1):
var actualBCR_Local_Moment = moment(actualBCR_Local);
值:Wed Aug 03 2016 04:10:00 GMT + 0100(GMT Daylight Time)
第3步(格式化12HR格式的演示文稿,这个问题在这里,因为我失去了3分钟,而原始值应该是04:10 ):
var actualBCR_Local_Formatted = actualBCR_Local_Moment.format(MM / DD / YYYY HH:MM);
value:08/03/2016 04:08
我可以防止以12HR格式格式化片刻时丢失分精确度吗?
这是因为您使用了错误的格式
在此
I've converted an ISO date string to a momentjs moment and then formatted that moment using .format("MM/DD/YYYY HH:MM")
.
When I output the final formatted moment, the minute value is incorrect as against the value read back from the iso string originally.
In this case the ISO string value holds 3:10 PM or "2016-08-03T03:10:00.000Z" as represented in the string. But when I call format the moment value is 4:07PM meaning three minutes have been subtracted during the format.
During debug I noted the following values at each assignment stage:
Step 1 (converting the db value to an ISO string):
var actualBCR_Local = moment.utc('@Model.Escalation.Actual_BCR_ISO').toISOString();
value: "2016-08-03T03:10:00.000Z"
Step 2 (converting the ISO string to a momentjs moment in order to represent the local time GMT+1):
var actualBCR_Local_Moment = moment(actualBCR_Local);
value: Wed Aug 03 2016 04:10:00 GMT+0100 (GMT Daylight Time)
Step 3 (formatting the moment in 12HR format for presentation, issue is here as I lose 3 minutes as against the original value which should be 04:10):
var actualBCR_Local_Formatted = actualBCR_Local_Moment.format("MM/DD/YYYY HH:MM");
value: "08/03/2016 04:08"
How can I prevent loss of minute precision when formatting a moment in 12HR format?
that's because you use the wrong format
In this section, you will find out that you are using HH:MM
which means hour:month
If you use HH:mm
then you will get correct time.
and that's why you got 2 minute loss, cause it display 08 as "month"
here is the what I tested
这篇关于如何在12HR中解决分钟精度格式化丢失的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!