C# UTC to Users Local Time

后端 未结 2 601
旧时难觅i
旧时难觅i 2020-12-30 15:28

I have a site where users can make posts. The users can be from all over the globe so when they post, I am storing the posted date as DateTime.UtcNow. I am using the JQuery

相关标签:
2条回答
  • 2020-12-30 16:15

    In general, you aren't going to know the user's exact time zone on the server side. Instead of trying to convert to the user's local time on the server side, send the time to the client in UTC and have the client convert the time. The TimeAgo plugin does this automatically as long as you give it the time in full ISO8601 format:

    <abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
    

    The Z at the end of the timestamp is important; that means UTC.

    0 讨论(0)
  • 2020-12-30 16:24

    Do you have the culture for the current user? If so you could convert to their timezone using code from C# - Convert UTC/GMT time to local time

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