Does getTimezoneOffset() contain Day Light Saving information and how do I get these both values?
Date stored in server at GMT+0 without Day Light Saving.
Client should receive it in it's own timezone format. So we can get time zone offset and summarize it with received date:
const currentTime = new Date();
this.timezoneOffset = currentTime.getTimezoneOffset();
Then we can check if client in DLS region somehow, for example using momentjs:
const isDaylightSavingTime = moment().isDST();
And there I can't figure out 3 things:
1) does getTimezoneOffset() already contain Day Light Saving information
2) and if not, what the better way to check is user in DST then moment (because I readed thet moment js have not some countries and cities in it's own base)
3) does Moment().add(Moment().utcOffset(), 'm') return date with Day Light Saving?
javascript date timezone momentjs timezone-offset
add a comment |
Date stored in server at GMT+0 without Day Light Saving.
Client should receive it in it's own timezone format. So we can get time zone offset and summarize it with received date:
const currentTime = new Date();
this.timezoneOffset = currentTime.getTimezoneOffset();
Then we can check if client in DLS region somehow, for example using momentjs:
const isDaylightSavingTime = moment().isDST();
And there I can't figure out 3 things:
1) does getTimezoneOffset() already contain Day Light Saving information
2) and if not, what the better way to check is user in DST then moment (because I readed thet moment js have not some countries and cities in it's own base)
3) does Moment().add(Moment().utcOffset(), 'm') return date with Day Light Saving?
javascript date timezone momentjs timezone-offset
add a comment |
Date stored in server at GMT+0 without Day Light Saving.
Client should receive it in it's own timezone format. So we can get time zone offset and summarize it with received date:
const currentTime = new Date();
this.timezoneOffset = currentTime.getTimezoneOffset();
Then we can check if client in DLS region somehow, for example using momentjs:
const isDaylightSavingTime = moment().isDST();
And there I can't figure out 3 things:
1) does getTimezoneOffset() already contain Day Light Saving information
2) and if not, what the better way to check is user in DST then moment (because I readed thet moment js have not some countries and cities in it's own base)
3) does Moment().add(Moment().utcOffset(), 'm') return date with Day Light Saving?
javascript date timezone momentjs timezone-offset
Date stored in server at GMT+0 without Day Light Saving.
Client should receive it in it's own timezone format. So we can get time zone offset and summarize it with received date:
const currentTime = new Date();
this.timezoneOffset = currentTime.getTimezoneOffset();
Then we can check if client in DLS region somehow, for example using momentjs:
const isDaylightSavingTime = moment().isDST();
And there I can't figure out 3 things:
1) does getTimezoneOffset() already contain Day Light Saving information
2) and if not, what the better way to check is user in DST then moment (because I readed thet moment js have not some countries and cities in it's own base)
3) does Moment().add(Moment().utcOffset(), 'm') return date with Day Light Saving?
javascript date timezone momentjs timezone-offset
javascript date timezone momentjs timezone-offset
edited Nov 18 '18 at 19:56
mr_blond
asked Nov 18 '18 at 19:38
mr_blondmr_blond
18811
18811
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
And there I can't figure out 3 things:
1) does getTimezoneOffset() already contain Day Light Saving information
Moment is a wrapper for ECMAScript Date objects. The timezone offset for a built–in Date instance is based on host system settings. Depending on the implementation, it may or may not reflect historic changes to timezones for the related date (i.e. the Date that the method is called on). It will at least reflect the current settings.
2) and if not, what the better way to check is user in DST then moment (because I readed thet moment js have not some countries and cities in it's own base)
You need to define "better". In addition to other libraries (e.g. Luxon), there are web APIs like timezonedb and Date.prototype.toLocaleString with the timeZone option that uses IANA location names like "Asia/Shanghai". You can also download and use the IANA timezone database if you wish.
3) does Moment().add(Moment().utcOffset(), 'm') return date with Day Light Saving?
You can't modify the timezone offset, there is only a getter, so any "local" date will have the timezone offset applied, whether that be the standard or daylight saving offset for the particular date and location. All the above does is shift the time by the offset, it doesn't change the timezone (unless it's shifted across a daylight saving boundary).
Date objects are UTC at heart, so the general approach is to use UTC for everything and only consider the timezone offset for presentation. That doesn't cover all scenarios, but it does the majority. The remaining cases require specific approaches based on use cases.
If you describe what you are trying to do, you might get more relevant answers.
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%2f53364735%2fdoes-gettimezoneoffset-contain-day-light-saving-information-and-how-do-i-get-t%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
And there I can't figure out 3 things:
1) does getTimezoneOffset() already contain Day Light Saving information
Moment is a wrapper for ECMAScript Date objects. The timezone offset for a built–in Date instance is based on host system settings. Depending on the implementation, it may or may not reflect historic changes to timezones for the related date (i.e. the Date that the method is called on). It will at least reflect the current settings.
2) and if not, what the better way to check is user in DST then moment (because I readed thet moment js have not some countries and cities in it's own base)
You need to define "better". In addition to other libraries (e.g. Luxon), there are web APIs like timezonedb and Date.prototype.toLocaleString with the timeZone option that uses IANA location names like "Asia/Shanghai". You can also download and use the IANA timezone database if you wish.
3) does Moment().add(Moment().utcOffset(), 'm') return date with Day Light Saving?
You can't modify the timezone offset, there is only a getter, so any "local" date will have the timezone offset applied, whether that be the standard or daylight saving offset for the particular date and location. All the above does is shift the time by the offset, it doesn't change the timezone (unless it's shifted across a daylight saving boundary).
Date objects are UTC at heart, so the general approach is to use UTC for everything and only consider the timezone offset for presentation. That doesn't cover all scenarios, but it does the majority. The remaining cases require specific approaches based on use cases.
If you describe what you are trying to do, you might get more relevant answers.
add a comment |
And there I can't figure out 3 things:
1) does getTimezoneOffset() already contain Day Light Saving information
Moment is a wrapper for ECMAScript Date objects. The timezone offset for a built–in Date instance is based on host system settings. Depending on the implementation, it may or may not reflect historic changes to timezones for the related date (i.e. the Date that the method is called on). It will at least reflect the current settings.
2) and if not, what the better way to check is user in DST then moment (because I readed thet moment js have not some countries and cities in it's own base)
You need to define "better". In addition to other libraries (e.g. Luxon), there are web APIs like timezonedb and Date.prototype.toLocaleString with the timeZone option that uses IANA location names like "Asia/Shanghai". You can also download and use the IANA timezone database if you wish.
3) does Moment().add(Moment().utcOffset(), 'm') return date with Day Light Saving?
You can't modify the timezone offset, there is only a getter, so any "local" date will have the timezone offset applied, whether that be the standard or daylight saving offset for the particular date and location. All the above does is shift the time by the offset, it doesn't change the timezone (unless it's shifted across a daylight saving boundary).
Date objects are UTC at heart, so the general approach is to use UTC for everything and only consider the timezone offset for presentation. That doesn't cover all scenarios, but it does the majority. The remaining cases require specific approaches based on use cases.
If you describe what you are trying to do, you might get more relevant answers.
add a comment |
And there I can't figure out 3 things:
1) does getTimezoneOffset() already contain Day Light Saving information
Moment is a wrapper for ECMAScript Date objects. The timezone offset for a built–in Date instance is based on host system settings. Depending on the implementation, it may or may not reflect historic changes to timezones for the related date (i.e. the Date that the method is called on). It will at least reflect the current settings.
2) and if not, what the better way to check is user in DST then moment (because I readed thet moment js have not some countries and cities in it's own base)
You need to define "better". In addition to other libraries (e.g. Luxon), there are web APIs like timezonedb and Date.prototype.toLocaleString with the timeZone option that uses IANA location names like "Asia/Shanghai". You can also download and use the IANA timezone database if you wish.
3) does Moment().add(Moment().utcOffset(), 'm') return date with Day Light Saving?
You can't modify the timezone offset, there is only a getter, so any "local" date will have the timezone offset applied, whether that be the standard or daylight saving offset for the particular date and location. All the above does is shift the time by the offset, it doesn't change the timezone (unless it's shifted across a daylight saving boundary).
Date objects are UTC at heart, so the general approach is to use UTC for everything and only consider the timezone offset for presentation. That doesn't cover all scenarios, but it does the majority. The remaining cases require specific approaches based on use cases.
If you describe what you are trying to do, you might get more relevant answers.
And there I can't figure out 3 things:
1) does getTimezoneOffset() already contain Day Light Saving information
Moment is a wrapper for ECMAScript Date objects. The timezone offset for a built–in Date instance is based on host system settings. Depending on the implementation, it may or may not reflect historic changes to timezones for the related date (i.e. the Date that the method is called on). It will at least reflect the current settings.
2) and if not, what the better way to check is user in DST then moment (because I readed thet moment js have not some countries and cities in it's own base)
You need to define "better". In addition to other libraries (e.g. Luxon), there are web APIs like timezonedb and Date.prototype.toLocaleString with the timeZone option that uses IANA location names like "Asia/Shanghai". You can also download and use the IANA timezone database if you wish.
3) does Moment().add(Moment().utcOffset(), 'm') return date with Day Light Saving?
You can't modify the timezone offset, there is only a getter, so any "local" date will have the timezone offset applied, whether that be the standard or daylight saving offset for the particular date and location. All the above does is shift the time by the offset, it doesn't change the timezone (unless it's shifted across a daylight saving boundary).
Date objects are UTC at heart, so the general approach is to use UTC for everything and only consider the timezone offset for presentation. That doesn't cover all scenarios, but it does the majority. The remaining cases require specific approaches based on use cases.
If you describe what you are trying to do, you might get more relevant answers.
answered Nov 18 '18 at 23:43
RobGRobG
98.1k19106146
98.1k19106146
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%2f53364735%2fdoes-gettimezoneoffset-contain-day-light-saving-information-and-how-do-i-get-t%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