Compare ISO 8601 date strings in javascript

前端 未结 1 2076
悲哀的现实
悲哀的现实 2021-02-20 14:43

I want to compare ISO 8601 dates in javascript as strings instead of making Date objects for each string and comparing objects.

var date_array = [\'2012-10-01\         


        
1条回答
  •  一生所求
    2021-02-20 15:01

    Using that comparison operator will look at the strings values lexicographically, which means the dictionary order.

    In ASCII, the decimal digits are sequentially stored smallest (0, 0x30) to largest (9, 0x39). If they're consistently in this format, largest value (year) to smallest (day) and always 0 padded to the largest possible value, then these comparisons will be fine.

    0 讨论(0)
提交回复
热议问题