Sort ISO 8601 dates forward or backwards

后端 未结 2 2002
情话喂你
情话喂你 2020-12-10 13:43

I have an array of dates in ISO8601 format and need to sort them. Does anyone have a suggestion for an algorithm that would work? I don\'t think they will sort as strings un

2条回答
  •  抹茶落季
    2020-12-10 14:00

    I don't think they will sort as strings unless I'm much mistaken,

    You are much mistaken :-). They will sort as strings. That's one of the major plus points of ISO 8601 over other date formats.

    See point 1: http://en.wikipedia.org/wiki/ISO_8601#General_principles

    ... The lexicographical order of the representation thus corresponds to chronological order...

    as long as you aren't dealing with negative years, an you are using the same timezone and subformat i.e. you don't mix month based and week based (thanks to @paxdiablo and @whiskeysierra for pointing these out)

提交回复
热议问题