get client time zone from browser
Look at this repository pageloom it is helpful
download jstz.min.js and add a function to your html page
<script language="javascript">
function getTimezoneName() {
timezone = jstz.determine()
return timezone.name();
}
</script>
and call this function from your display tag
Getting the client's time zone (and offset) in JavaScript
Using getTimezoneOffset()
You can get the time zone offset in minutes like this:
var offset = new Date().getTimezoneOffset();
console.log(offset);
// if offset equals -60 then the time zone offset is UTC+01
Get client's timezone offset in ExpressJS
If you control the client, you can do this with client-side JavaScript.
If you don't (e.g. you're building a server-side component like an API), then you can't pull it out of the HTTP request (unless you're using sessions, but even that's not necessarily reliable).
On the upside, if it's only server-side, you shouldn't worry about it either: set all your date objects as UTC or a Unix timestamp and leave it to the client developer to handle timezones.
How to get clients Time zone in JavaScript?
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
Demo
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>
Get timezone from users browser using moment(timezone).js
var timedifference = new Date().getTimezoneOffset();
This returns the difference from the clients timezone from UTC time.
You can then play around with it as you like.
How to get Client side time zone
code that works for me...
<script type="text/javascript" language="javascript" >
function fnLoad()
{
var objLocalZone = new Date();
var strLocalZone=''+objLocalZone;
var mySplitResult = strLocalZone.split(" ");
var newLocalZone = mySplitResult[5].slice(0,mySplitResult[5].length-2) +':'+mySplitResult[5].slice(mySplitResult[5].length-2,mySplitResult[5].length);
document.getElementById("hdnTimeZone").value = newLocalZone;
//alert('Length : '+newLocalZone);
}
</script>
hidden input
<input type="hidden" id="hdnTimeZone" name="hdnTimeZone"/>
i don't know this is proper way to get client(visitor)'s timezone. but it works fine for me.If anybody have optimum solution this let me know. thanks...
How to get client's timezone?
Check out this article on how to detect the timezone by setting a Cookie through JavaScript that will hold the client's timezone. It's rather lenghty, but that is because it is quite verbose. I've implemented a solution along these lines in one of my own apps and it works quite well.
You could also send the timezone via Ajax to the server and have it do whatever you need to do it with then. Or, if you are not doing any serverside calculations with it, just apply the timezone client side where needed. Really depends on your usecase.
In addition to that, I suggest you let the visitor set his timezone himself and store that in the Cookie or a Session.
How to detect the timezone of a client?
Unfortunately this information is not passed in HTTP headers.
Usually you need cooperating JavaScript to fetch it for you.
Web is full of examples, here is one http://www.coderanch.com/t/486127/JSP/java/Query-timezone
Related Topics
Explode String into Array With No Empty Elements
Laravel - Session Store Not Set on Request
Get Difference Between Associative Rows of Two 2-Dimensional Arrays
PHP Get Site Url Protocol - Http VS Https
Upload Video Files Via PHP and Save Them in Appropriate Folder and Have a Database Entry
Regexp to Add Attribute in Any Xml Tags
What's the Difference Between ++$I and $I++ in PHP
PHP Header Redirect Not Working
Export MySQL Data to Excel in PHP
How to Get the Real Url After File_Get_Contents If Redirection Happens
If Statement in the Middle of Concatenation
Symfony2 Conceptual Issue: General Bundles Vs. Specific Ones
How to Check If the Current Date/Time Is Past a Set Date/Time
Assigning the Return Value of New by Reference Is Deprecated