PHP date format /Date(1365004652303-0500)/

后端 未结 10 1132
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 05:56

I am calling an API from where I am getting date /Date(1365004652303-0500)/, I don\'t understand what format this is. How is this date format called? I was not

10条回答
  •  悲&欢浪女
    2020-11-27 06:21

    I had some slightly different experience which led me to make a couple of slight changes to Baba's excellent answer.

    Using Newtonsoft's JSON library to encode messages in .NET, which I then send to our website (the PHP part), I get a space before the timezone offset, and no +/- character.

    I have also seen negative numbers from pre-epoch dates which means I needed to cater for a - sign before the millisecond value.

    I altered the regex to this and it works perfectly for me:

    ^/Date(([-]?\d{10})(\d{3})\s?([+-]?\d{4}))/$

    The two differences are

    [-]? before the 10-digit millisecond value, and \s? before the timezone offset.

    I would put this as a comment on Baba's answer, but my lack of reputation doesn't permit me. I hope this is appropriate for me to post here as I thought it might be useful.

提交回复
热议问题