0

i am in situation where i need to get user pc timezone info by JavaScript. if i get the timezone info then i like to feed those info to Noda Time library just to get user side current date and time.

the reason i need to get user side date and time based on user pc timezone because i do not want to depend on user pc date & time because i am developing a sensitive apps where we need to show timezone wise date. i could easily fetch user pc date & time but there is one risk if user change his date & time then we will not be able to detect it at runtime.

same way user can change his timezone but it is rare case.

here i got a .net code where we could put zoneid and get current date time based on timezone info.

var zone = TimeZoneInfo.FindSystemTimeZoneById(zoneId);
var now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, zone);

same way using noda library i got a code where we could put zoneid and get current date time based on timezone info.

// zoneId is the TZDB ID, e.g. "Europe/London"
DateTimeZone zone = DateTimeZoneProviders.Tzdb[zoneId];
// clock would be an IClock implementation of some description; rather than
// having a static method, an interface encourages testability. 
ZonedDateTime now = clock.Now.InZone(zone);

so my question is how to get zoneid by javascript and next i need to get user pc local time based on zoneid which i could put to .net datetime class or noda library.

if anyone has any idea then please share with me to achieve my goal. thanks

Thomas
  • 33,544
  • 126
  • 357
  • 626
  • You might want to have a look at http://momentjs.com & http://momentjs.com/timezone/ – Marvin Smit Oct 28 '14 at 08:23
  • http://stackoverflow.com/questions/246498/creating-a-datetime-in-a-specific-time-zone-in-c-sharp-fx-3-5 – Thomas Oct 28 '14 at 08:25
  • how timezone zoneId would look like? – Thomas Oct 28 '14 at 08:27
  • @MarvinSmit—note in the OP: "*i do not want to depend on user pc date & time*". – RobG Oct 28 '14 at 08:52
  • The timezone data you get from the javascript Date object is based on system settings, so if they are wrong, then so is your data. – RobG Oct 28 '14 at 08:54
  • yes it is true that client pc timezone setting could be wrong but i want to get user local time based on user pc timezone info if it is wrong setting too. any idea? – Thomas Oct 28 '14 at 09:18
  • A similar question was asked here but it doesn't have a satisfactory answer AFAIC: http://stackoverflow.com/q/13365399/397817 This looks more promising, using moment.js as suggested by @MarvinSmit http://stackoverflow.com/q/19420582/397817 – Stephen Kennedy Oct 28 '14 at 09:40

0 Answers0