Javascript/PHP and timezones

后端 未结 5 1734
一个人的身影
一个人的身影 2020-12-11 05:54

I\'d like to be able to guess the user\'s timezone offset and whether or not daylight savings is being applied. Currently, the most definitive code that I\'ve found for this

5条回答
  •  暖寄归人
    2020-12-11 06:21

    If you want to rely on javascript you can simply send the utc time/timestamp back and forth and let the client convert it to its local time representation.

    edit: simple self-contained example (using jquery)

    
      
        ...
        
        
      
      
        

    If javascript is not available the user still sees a date/time though it's in UTC.
    edit2: And there is a javascript library (or was it even a jquery plugin?) that does this kind of things plus some nifty conversions like "an hour ago", "last week" ..something like that. But I forgot the name :(

提交回复
热议问题