直接比较Javascript ISO日期字符串是否安全? [英] Is direct comparison of Javascript ISO Date Strings safe?

查看:39
本文介绍了直接比较Javascript ISO日期字符串是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像这样直接比较ISO日期字符串是否安全:

Is it safe to directly compare ISO Date Strings like this:

"2018-03-16T18:00:00.000z">"2018-04-16T18:00:00.000z"//否

似乎只要使用前导零(正确的ISO格式),此比较就很安全,并且不需要将值转换为日期对象.我在俯视什么吗?

It seems as long as leading zeros are used (proper ISO formatting) this comparison is safe and there is no need to convert the values to Date Objects. Am I overlooking something?

推荐答案

使用给定格式的 ISO8601 时间,

2018-03-16T18:00:00.000Z
                       ^

您可以使用直接字符串比较,因为给定的时区是一个

you could use a direct string comparison, because the given time zone is a

世界标准时间(UTC)

如果时间以UTC表示,则在时间后直接添加一个Z,不能带空格.Z是零UTC偏移量的区域标记."09:30 UTC"因此,表示为"09:30Z".或"0930Z"."14:45:15 UTC"将为"14:45:15Z"或"144515Z".

Coordinated Universal Time (UTC)

If the time is in UTC, add a Z directly after the time without a space. Z is the zone designator for the zero UTC offset. "09:30 UTC" is therefore represented as "09:30Z" or "0930Z". "14:45:15 UTC" would be "14:45:15Z" or "144515Z".

这篇关于直接比较Javascript ISO日期字符串是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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