Getting client's TimeZone without using the normal JavaScript funtion 'getTimezoneOffset'?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am currently working on a registration form on a site, and I need to know exactly how to get the Timezone Offset for an active user-client to calculate his actual local time (no need for DST).
I've tried the JS method using the function getTimeZoneOffset() but it seems that it not very recommended because it is relying on the user Time Settings.
(I changed the clock time on my machine and try it)
So any change in the user time settings will alter the timezone offset.
Are there any other 'robust' and 'trustworthy' methods that can I implement to get the timezone offset and then apply it inside my C# code.
Best.
javascript c# timezone client-server timezone-offset
add a comment |
I am currently working on a registration form on a site, and I need to know exactly how to get the Timezone Offset for an active user-client to calculate his actual local time (no need for DST).
I've tried the JS method using the function getTimeZoneOffset() but it seems that it not very recommended because it is relying on the user Time Settings.
(I changed the clock time on my machine and try it)
So any change in the user time settings will alter the timezone offset.
Are there any other 'robust' and 'trustworthy' methods that can I implement to get the timezone offset and then apply it inside my C# code.
Best.
javascript c# timezone client-server timezone-offset
i think you might be able to find an answer to your question here stackoverflow.com/questions/1091372/…
– Salim Proctor
Jan 3 at 15:22
add a comment |
I am currently working on a registration form on a site, and I need to know exactly how to get the Timezone Offset for an active user-client to calculate his actual local time (no need for DST).
I've tried the JS method using the function getTimeZoneOffset() but it seems that it not very recommended because it is relying on the user Time Settings.
(I changed the clock time on my machine and try it)
So any change in the user time settings will alter the timezone offset.
Are there any other 'robust' and 'trustworthy' methods that can I implement to get the timezone offset and then apply it inside my C# code.
Best.
javascript c# timezone client-server timezone-offset
I am currently working on a registration form on a site, and I need to know exactly how to get the Timezone Offset for an active user-client to calculate his actual local time (no need for DST).
I've tried the JS method using the function getTimeZoneOffset() but it seems that it not very recommended because it is relying on the user Time Settings.
(I changed the clock time on my machine and try it)
So any change in the user time settings will alter the timezone offset.
Are there any other 'robust' and 'trustworthy' methods that can I implement to get the timezone offset and then apply it inside my C# code.
Best.
javascript c# timezone client-server timezone-offset
javascript c# timezone client-server timezone-offset
asked Jan 3 at 15:13
user1924180user1924180
85
85
i think you might be able to find an answer to your question here stackoverflow.com/questions/1091372/…
– Salim Proctor
Jan 3 at 15:22
add a comment |
i think you might be able to find an answer to your question here stackoverflow.com/questions/1091372/…
– Salim Proctor
Jan 3 at 15:22
i think you might be able to find an answer to your question here stackoverflow.com/questions/1091372/…
– Salim Proctor
Jan 3 at 15:22
i think you might be able to find an answer to your question here stackoverflow.com/questions/1091372/…
– Salim Proctor
Jan 3 at 15:22
add a comment |
1 Answer
1
active
oldest
votes
There's a lot to unwind here, so I'll go point by point of your question:
... I need to know exactly how to get the Timezone Offset for an active user ...
You can't get the time zone offset, you can only get a time zone offset. That is, the time zone offset you obtain is for a single point in time only. Time zones go through transitions, due to changes in standard time, and due to daylight saving time. When you call getTimeZoneOffset
on a JavaScript Date
object, that Date
object is representing a particular point in time (by default, "now"). Thus, the offset returned is for that particular point in time. There is no guarantee that a previous point in time or a future point in time will use the same offset. Sending the offset to the server is only useful if you are pairing it with that specific timestamp (such as logging activities using a DateTimeOffset pattern).
Read also, the "Time Zone != Offset" section of the timezone tag wiki.
... to calculate his actual local time ...
You don't need to calculate that. new Date().toString()
will give you the user's actual local time. If you need the output in a specific format, you can use libraries like Luxon, Date-fns, Moment.js, and others, or you can use a function like this one.
... (no need for DST).
People say this often because they are thinking it removes complexities, but the fact of the matter is - that's not up to you. Whether DST applies or not (and when) is up to the local government agency that regulates the specific time zone in question. If DST is applicable in the local time of your user at the time in question, and if you decide not to take that into account, then your results will be an hour off (usually).
Fortunately, all the hard work has already been done for you. A lot of people work diligently to ensure that time zone databases are kept accurate. It is easier to consume their efforts than to try to work around them.
Also, even if you think you don't care about daylight saving time, consider that many time zones have transitions created by changes in their standard time.
...
getTimeZoneOffset()
but it seems that it not very recommended because it is relying on the user Time Settings. ...
That it relies on user time settings is not a problem. The general reason it's not recommended is because of the "Time Zone != Offset" issue that I described already. If you want to know the user's time zone, you need a time zone identifier like "America/Los_Angeles"
, not an offset of 480
.
... So any change in the user time settings will alter the timezone offset.
The user is in control of their own computer, and can set the time zone to anything they want. Usually people set the time zone to their local time, such that the clocks they see are correct. It's not unheard of for people to use other time zones, such as if they work overseas and want to align their work day to their parent company's local time (though personally, I would find that abhorrent). At any rate, it's not something you can reasonably expect to control.
... Are there any other 'robust' and 'trustworthy' methods that can I implement to get the timezone offset and then apply it inside my C# code.
If you want the user's local time zone, then use one of the methods listed here.
However, I'm not sure by what criteria you consider "robust and trustworthy". There's nothing particularly untrustworthy about the aforementioned methods...
One thing you might consider is if you actually don't want the user's local time zone, but rather the local time in a particular location. While these seem like the same thing, they're not always. You can derive the local time zone identifier of a location using one of the methods listed here.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025030%2fgetting-clients-timezone-without-using-the-normal-javascript-funtion-gettimezo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There's a lot to unwind here, so I'll go point by point of your question:
... I need to know exactly how to get the Timezone Offset for an active user ...
You can't get the time zone offset, you can only get a time zone offset. That is, the time zone offset you obtain is for a single point in time only. Time zones go through transitions, due to changes in standard time, and due to daylight saving time. When you call getTimeZoneOffset
on a JavaScript Date
object, that Date
object is representing a particular point in time (by default, "now"). Thus, the offset returned is for that particular point in time. There is no guarantee that a previous point in time or a future point in time will use the same offset. Sending the offset to the server is only useful if you are pairing it with that specific timestamp (such as logging activities using a DateTimeOffset pattern).
Read also, the "Time Zone != Offset" section of the timezone tag wiki.
... to calculate his actual local time ...
You don't need to calculate that. new Date().toString()
will give you the user's actual local time. If you need the output in a specific format, you can use libraries like Luxon, Date-fns, Moment.js, and others, or you can use a function like this one.
... (no need for DST).
People say this often because they are thinking it removes complexities, but the fact of the matter is - that's not up to you. Whether DST applies or not (and when) is up to the local government agency that regulates the specific time zone in question. If DST is applicable in the local time of your user at the time in question, and if you decide not to take that into account, then your results will be an hour off (usually).
Fortunately, all the hard work has already been done for you. A lot of people work diligently to ensure that time zone databases are kept accurate. It is easier to consume their efforts than to try to work around them.
Also, even if you think you don't care about daylight saving time, consider that many time zones have transitions created by changes in their standard time.
...
getTimeZoneOffset()
but it seems that it not very recommended because it is relying on the user Time Settings. ...
That it relies on user time settings is not a problem. The general reason it's not recommended is because of the "Time Zone != Offset" issue that I described already. If you want to know the user's time zone, you need a time zone identifier like "America/Los_Angeles"
, not an offset of 480
.
... So any change in the user time settings will alter the timezone offset.
The user is in control of their own computer, and can set the time zone to anything they want. Usually people set the time zone to their local time, such that the clocks they see are correct. It's not unheard of for people to use other time zones, such as if they work overseas and want to align their work day to their parent company's local time (though personally, I would find that abhorrent). At any rate, it's not something you can reasonably expect to control.
... Are there any other 'robust' and 'trustworthy' methods that can I implement to get the timezone offset and then apply it inside my C# code.
If you want the user's local time zone, then use one of the methods listed here.
However, I'm not sure by what criteria you consider "robust and trustworthy". There's nothing particularly untrustworthy about the aforementioned methods...
One thing you might consider is if you actually don't want the user's local time zone, but rather the local time in a particular location. While these seem like the same thing, they're not always. You can derive the local time zone identifier of a location using one of the methods listed here.
add a comment |
There's a lot to unwind here, so I'll go point by point of your question:
... I need to know exactly how to get the Timezone Offset for an active user ...
You can't get the time zone offset, you can only get a time zone offset. That is, the time zone offset you obtain is for a single point in time only. Time zones go through transitions, due to changes in standard time, and due to daylight saving time. When you call getTimeZoneOffset
on a JavaScript Date
object, that Date
object is representing a particular point in time (by default, "now"). Thus, the offset returned is for that particular point in time. There is no guarantee that a previous point in time or a future point in time will use the same offset. Sending the offset to the server is only useful if you are pairing it with that specific timestamp (such as logging activities using a DateTimeOffset pattern).
Read also, the "Time Zone != Offset" section of the timezone tag wiki.
... to calculate his actual local time ...
You don't need to calculate that. new Date().toString()
will give you the user's actual local time. If you need the output in a specific format, you can use libraries like Luxon, Date-fns, Moment.js, and others, or you can use a function like this one.
... (no need for DST).
People say this often because they are thinking it removes complexities, but the fact of the matter is - that's not up to you. Whether DST applies or not (and when) is up to the local government agency that regulates the specific time zone in question. If DST is applicable in the local time of your user at the time in question, and if you decide not to take that into account, then your results will be an hour off (usually).
Fortunately, all the hard work has already been done for you. A lot of people work diligently to ensure that time zone databases are kept accurate. It is easier to consume their efforts than to try to work around them.
Also, even if you think you don't care about daylight saving time, consider that many time zones have transitions created by changes in their standard time.
...
getTimeZoneOffset()
but it seems that it not very recommended because it is relying on the user Time Settings. ...
That it relies on user time settings is not a problem. The general reason it's not recommended is because of the "Time Zone != Offset" issue that I described already. If you want to know the user's time zone, you need a time zone identifier like "America/Los_Angeles"
, not an offset of 480
.
... So any change in the user time settings will alter the timezone offset.
The user is in control of their own computer, and can set the time zone to anything they want. Usually people set the time zone to their local time, such that the clocks they see are correct. It's not unheard of for people to use other time zones, such as if they work overseas and want to align their work day to their parent company's local time (though personally, I would find that abhorrent). At any rate, it's not something you can reasonably expect to control.
... Are there any other 'robust' and 'trustworthy' methods that can I implement to get the timezone offset and then apply it inside my C# code.
If you want the user's local time zone, then use one of the methods listed here.
However, I'm not sure by what criteria you consider "robust and trustworthy". There's nothing particularly untrustworthy about the aforementioned methods...
One thing you might consider is if you actually don't want the user's local time zone, but rather the local time in a particular location. While these seem like the same thing, they're not always. You can derive the local time zone identifier of a location using one of the methods listed here.
add a comment |
There's a lot to unwind here, so I'll go point by point of your question:
... I need to know exactly how to get the Timezone Offset for an active user ...
You can't get the time zone offset, you can only get a time zone offset. That is, the time zone offset you obtain is for a single point in time only. Time zones go through transitions, due to changes in standard time, and due to daylight saving time. When you call getTimeZoneOffset
on a JavaScript Date
object, that Date
object is representing a particular point in time (by default, "now"). Thus, the offset returned is for that particular point in time. There is no guarantee that a previous point in time or a future point in time will use the same offset. Sending the offset to the server is only useful if you are pairing it with that specific timestamp (such as logging activities using a DateTimeOffset pattern).
Read also, the "Time Zone != Offset" section of the timezone tag wiki.
... to calculate his actual local time ...
You don't need to calculate that. new Date().toString()
will give you the user's actual local time. If you need the output in a specific format, you can use libraries like Luxon, Date-fns, Moment.js, and others, or you can use a function like this one.
... (no need for DST).
People say this often because they are thinking it removes complexities, but the fact of the matter is - that's not up to you. Whether DST applies or not (and when) is up to the local government agency that regulates the specific time zone in question. If DST is applicable in the local time of your user at the time in question, and if you decide not to take that into account, then your results will be an hour off (usually).
Fortunately, all the hard work has already been done for you. A lot of people work diligently to ensure that time zone databases are kept accurate. It is easier to consume their efforts than to try to work around them.
Also, even if you think you don't care about daylight saving time, consider that many time zones have transitions created by changes in their standard time.
...
getTimeZoneOffset()
but it seems that it not very recommended because it is relying on the user Time Settings. ...
That it relies on user time settings is not a problem. The general reason it's not recommended is because of the "Time Zone != Offset" issue that I described already. If you want to know the user's time zone, you need a time zone identifier like "America/Los_Angeles"
, not an offset of 480
.
... So any change in the user time settings will alter the timezone offset.
The user is in control of their own computer, and can set the time zone to anything they want. Usually people set the time zone to their local time, such that the clocks they see are correct. It's not unheard of for people to use other time zones, such as if they work overseas and want to align their work day to their parent company's local time (though personally, I would find that abhorrent). At any rate, it's not something you can reasonably expect to control.
... Are there any other 'robust' and 'trustworthy' methods that can I implement to get the timezone offset and then apply it inside my C# code.
If you want the user's local time zone, then use one of the methods listed here.
However, I'm not sure by what criteria you consider "robust and trustworthy". There's nothing particularly untrustworthy about the aforementioned methods...
One thing you might consider is if you actually don't want the user's local time zone, but rather the local time in a particular location. While these seem like the same thing, they're not always. You can derive the local time zone identifier of a location using one of the methods listed here.
There's a lot to unwind here, so I'll go point by point of your question:
... I need to know exactly how to get the Timezone Offset for an active user ...
You can't get the time zone offset, you can only get a time zone offset. That is, the time zone offset you obtain is for a single point in time only. Time zones go through transitions, due to changes in standard time, and due to daylight saving time. When you call getTimeZoneOffset
on a JavaScript Date
object, that Date
object is representing a particular point in time (by default, "now"). Thus, the offset returned is for that particular point in time. There is no guarantee that a previous point in time or a future point in time will use the same offset. Sending the offset to the server is only useful if you are pairing it with that specific timestamp (such as logging activities using a DateTimeOffset pattern).
Read also, the "Time Zone != Offset" section of the timezone tag wiki.
... to calculate his actual local time ...
You don't need to calculate that. new Date().toString()
will give you the user's actual local time. If you need the output in a specific format, you can use libraries like Luxon, Date-fns, Moment.js, and others, or you can use a function like this one.
... (no need for DST).
People say this often because they are thinking it removes complexities, but the fact of the matter is - that's not up to you. Whether DST applies or not (and when) is up to the local government agency that regulates the specific time zone in question. If DST is applicable in the local time of your user at the time in question, and if you decide not to take that into account, then your results will be an hour off (usually).
Fortunately, all the hard work has already been done for you. A lot of people work diligently to ensure that time zone databases are kept accurate. It is easier to consume their efforts than to try to work around them.
Also, even if you think you don't care about daylight saving time, consider that many time zones have transitions created by changes in their standard time.
...
getTimeZoneOffset()
but it seems that it not very recommended because it is relying on the user Time Settings. ...
That it relies on user time settings is not a problem. The general reason it's not recommended is because of the "Time Zone != Offset" issue that I described already. If you want to know the user's time zone, you need a time zone identifier like "America/Los_Angeles"
, not an offset of 480
.
... So any change in the user time settings will alter the timezone offset.
The user is in control of their own computer, and can set the time zone to anything they want. Usually people set the time zone to their local time, such that the clocks they see are correct. It's not unheard of for people to use other time zones, such as if they work overseas and want to align their work day to their parent company's local time (though personally, I would find that abhorrent). At any rate, it's not something you can reasonably expect to control.
... Are there any other 'robust' and 'trustworthy' methods that can I implement to get the timezone offset and then apply it inside my C# code.
If you want the user's local time zone, then use one of the methods listed here.
However, I'm not sure by what criteria you consider "robust and trustworthy". There's nothing particularly untrustworthy about the aforementioned methods...
One thing you might consider is if you actually don't want the user's local time zone, but rather the local time in a particular location. While these seem like the same thing, they're not always. You can derive the local time zone identifier of a location using one of the methods listed here.
answered Jan 3 at 19:06
Matt JohnsonMatt Johnson
143k42289414
143k42289414
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025030%2fgetting-clients-timezone-without-using-the-normal-javascript-funtion-gettimezo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
i think you might be able to find an answer to your question here stackoverflow.com/questions/1091372/…
– Salim Proctor
Jan 3 at 15:22