-2

How to get the IST current date and time using java script with out help of local client system time.

var dt = new Date();
var time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
$("#dbTimeIn").val(time);
$("#dbTimeOut").val(time);
  • It will give you indian standard time only if you are using in india, or the local standard time. If you specifically want indian standard time, then in UTC time add 31800000 milliseconds. – Vaibhav Feb 23 '15 at 12:11
  • http://stackoverflow.com/a/6777470/402037 + "Indian Standard Time (IST) is the time observed throughout India and Sri Lanka, with a time offset of UTC+05:30" – Andreas Feb 23 '15 at 12:14
  • yes vaibhav. my requirement is to take employee time in and time out inside office. but suppose in system time is wrong. its take same time. – user3259676 Feb 23 '15 at 12:15
  • `var dt = new Date('<%=a_value_from_the_server %>') ;` – Alex K. Feb 23 '15 at 12:29

1 Answers1

1

Last time I checked there is no Javascript library that correctly parses the Olson Timezone Database, and there is no native support for it either, so if you want this, I'm afraid you'll have to implement it yourself.

You would do a great many people a favor if you did write a library which does this. Be weary of libraries that claim they do, like timezone-js, cause they actually don't work.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
  • For examples of good date-time libraries, see the either of these Java-based ones: [Joda-Time](http://www.joda.org/joda-time/) or the new [java.time](http://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html) package built into Java 8 (and inspired by Joda-Time). Not a simple matter. As the Answer says, apparently no comparable library exists for JavaScript/EcmaScript. – Basil Bourque Feb 23 '15 at 18:42