3

How many online forum like StackOverflow and forum.asp.net show questions and posted answers with date and time?

How do they store date and time into sql server table?

Do they store date and time in UTC format?

Sometimes a forum shows a question asked 8 hours ago and also an answer posted 6.10 minutes ago.

How they diff stored utc date and time from current date and time? And how they diff stored utc date and time from user time zone time?

Suppose my website and database is hosted in an USA server. Suppose someone asked a question in the morning of Aug 21 at 9:34 from India and an answer was posted from USA on AUG 20 at night but forum shows the infos like:

question posted Aug 21 at 9:34

and answer posted Aug 21 at 9:38

How it is possible? Is it showing right date and time?

Please discuss how we should store date and time in sql server db in UTC format and how to display results which will not create confusion in readers mind.

Guide me using concepts and examples. People can visit any forum question without any login. So how server will know from which country the user is coming and what is user timezone? In asp.net can we know what is user time zone from server side?

When user requests a page then from the code being file can we know what is user timezone?

I saw forum generate posted question and answer's date and time info at server end before transfer html to client. So how any web site know from which time zone a user requesting a page. If it is possible then we can convert date and time to user timezone.

Looking for guide lines. Thanks

Gargaroz
  • 313
  • 9
  • 28
Thomas
  • 33,544
  • 126
  • 357
  • 626

1 Answers1

2

Generally speaking, dates and times should be stored in UTC and only displayed to local time in the UI layer.

StackOverflow uses client-side JavaScript to transform this:

<span title="2015-08-28 09:19:09Z" class="relativetime" />

into

<span title="2015-08-28 09:19:09Z" class="relativetime">24 mins ago</span>

(timeago is an example of a jQuery plugin that does this trick).

This made possible by the fact that JavaScript is executing client-side, and as such it knows what is the time zone of the "browser", as it were.

Determining time zone from within an ASP.NET web application is tricky.

Community
  • 1
  • 1
Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
  • one question. suppose i have search something in google and one stackoverflow link comes on which i click and then a page load in my browser. so when page load into my browser then response is generated at server side then how javascript can convert date and time to local one as per user timezone because date and time is generated at server side. – Thomas Aug 28 '15 at 09:57
  • @Thomas The `Z` part in `2015-08-28 09:19:09Z` tells JavaScript that this is a UTC time. If you know your local timezone offset, conversion from UTC to local time is trivial. – Anton Gogolev Aug 28 '15 at 10:21
  • so u mean to say UTC render from server side and when page download at client pc then we have to use some js library like moment.js to convert this UTC date and time 2015-08-28 09:19:09Z to local time ? am i getting u properly? – Thomas Aug 28 '15 at 11:29
  • what `Z` denote in date time data ? z denote it is UTC or something else ? – Thomas Aug 28 '15 at 11:33
  • @Thomas Using client-side JS will be the simplest solution. And yes, Z denotes [UTC](https://en.wikipedia.org/wiki/ISO_8601#UTC) – Anton Gogolev Aug 28 '15 at 11:45
  • thanks for your answer but it would be very nice if you discuss how to achieve with example code. thanks – Thomas Aug 28 '15 at 12:27