who can write a function to get clients Time zone,return value like:EDT
EST
IST
and so on
toTimeString()
method give time with the timezone name try out below...
var d=new Date();
var n=d.toTimeString();
ouput
03:41:07 GMT+0800 (PHT) or 09:43:01 EDT
or
Check : Automatic Timezone Detection Using JavaScript
download jstz.min.js and add a function to your html page
<script language="javascript">
function getTimezoneName() {
timezone = jstz.determine_timezone()
return timezone.name();
}
</script>
Use the Date().getTimezoneOffset() function and then build a hash table from this URL timeanddate to relate it to if you want to use the time zone value.
If you look at the result of calling the toString
method of a Date object, you'll get a value that's something like "Tue Apr 24 2012 23:30:54 GMT+1000 (AUS Eastern Standard Time)". This will depend on what your system locale is set to.
From there you can match each capital letter within the parentheses.
var paren = new Date().toString().match(/\(.+\)/);
return paren ? paren[0].match(/([A-Z])/g).join("") : "";
The catch is that not every browser will include the parenthesised values.
If you're targeting Firefox with a known Java plugin, you can also exploit the java
object in Javascript to create a new TimeZone (java.util.TimeZone) object based on a name (eg. "America/Los_Angeles"), then call the getDisplayName
method to give you the name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With