Timeline for Parse date without timezone javascript
Current License: CC BY-SA 4.0
18 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 9 at 21:48 | comment | added | En Kratia | @wensiso, thank you | |
| May 9 at 21:43 | comment | added | En Kratia | @Joe Maffei, it returns date with timezone * x2, Maybe it should have minus instead of plus as 'wensiso' wrote above? | |
| S Apr 11, 2024 at 4:12 | history | suggested | CommunityBot | CC BY-SA 4.0 |
Fixing expression, it was subtracting from date.getTime() but it must add to it;
|
| Apr 8, 2024 at 18:12 | review | Suggested edits | |||
| S Apr 11, 2024 at 4:12 | |||||
| Jan 16, 2023 at 20:58 | comment | added | Joe Maffei |
@wensiso you could avoid the if statement by using Math.sign: return new Date(date.getTime() + userTimezoneOffset * Math.sign(userTimezoneOffset));
|
|
| Aug 18, 2022 at 19:59 | comment | added | wensiso | This is a good answer, but it's incomplete depending on the offset value. Here is a function for this task: ` /** * Remove timezone offset from date. */ function removeTimezoneOffset(date) { let userTimezoneOffset = date.getTimezoneOffset() * 60000; if(userTimezoneOffset >= 0) { return new Date(date.getTime() - userTimezoneOffset); } return new Date(date.getTime() + userTimezoneOffset); } ` | |
| Oct 1, 2021 at 14:23 | comment | added | era s'q |
It should be new Date(date.getTime() + userTimezoneOffset); as - will affect the timezone ahead of utc.
|
|
| Apr 10, 2020 at 17:34 | comment | added | Rami Alloush |
Just to confirm, now this date is UTC time, and the valueOf() on it will return Unix Timestamp, correct?
|
|
| Nov 13, 2018 at 14:58 | comment | added | barbsan |
@vaindil now the result is the same as new Date('2016-08-25T00:00:00Z') I think the point was to manipulate new Date('2016-08-25T00:00:00Z') so that local time is displayed with time 0:00 but this code missed Z
|
|
| Nov 13, 2018 at 14:15 | comment | added | saran3h | Ah! spoke too soon. It doesn't work for most of the timezones. I can confirm that it returns a wrong date when offsetting AEST & CEST times with GMT time. | |
| S Sep 16, 2018 at 15:12 | history | edited | Luca Kiebel | CC BY-SA 4.0 |
getTimezoneOffset()- method will return negative or positive offset. Your solution works only when you are correct side of Greenwich. So this will work for some but not for everybody.
|
| S Sep 16, 2018 at 15:12 | history | suggested | Janne Harju | CC BY-SA 4.0 |
getTimezoneOffset()- method will return negative or positive offset. Your solution works only when you are correct side of Greenwich. So this will work for some but not for everybody.
|
| Sep 16, 2018 at 13:39 | review | Suggested edits | |||
| S Sep 16, 2018 at 15:12 | |||||
| Sep 16, 2018 at 13:35 | comment | added | Janne Harju | I will agree with @vaindil you should substracted. wakwa's solution works only when you are correct side of Greenwich. Wakwas should correct it. | |
| Aug 25, 2018 at 15:04 | comment | added | vaindil |
Unless I'm a complete idiot, this actually returns the wrong time. getTimezoneOffset() returns the number of minutes in the opposite direction that you'd think--my timezone is UTC-4 right now but getTimezoneOffset() returns a positive 240. Therefore userTimezoneOffset should be subtracted from date.getTime(), not added to it.
|
|
| Mar 17, 2017 at 12:29 | history | edited | Serge | CC BY-SA 3.0 |
The answer did not take daylight saving into account
|
| Mar 10, 2017 at 22:28 | comment | added | muj |
I have the same issue and found this to be helpful. However, I found that this doesn't handle time zone offsets due to daylight savings time. Example: I'm in PST so my current offset (in March) from GMT is -8:00, but in May it would be -7:00. My solution was to calculate var userTimezoneOffset = date.getTimezoneOffset()*60000;
|
|
| Aug 29, 2016 at 15:25 | history | answered | wawka | CC BY-SA 3.0 |