The Brasilia Summer Time 2019 at JavaScript - javascript

I have my datacenter in Brazil and all my JS applications have a Timezone problem because at 2019 the daylight save hour is not enable and the JS Server (NodeJS) understand the Brasil with -2 timezone but I need -3 .
I tried :
console.log(new Date()); // Sun Nov 10 2019 11:09:35 GMT-0200 (Brasilia Summer Time)
console.log(new Date().toISOString()); //2019-11-10T13:09:35.653Z

I believe you'll get the correct timezone offset if you upgrade your version of Node.js, it has been updated to reflect the timezone changes: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V12.md#12.13.1.
I believe Node 12.13.1 will show the correct UTC offset (-3 hours), e.g. in node 12.13.1 if I do:
console.log(new Date().toString());
I get
'Mon Dec 02 2019 11:28:26 GMT-0300 (Brasilia Standard Time)'

Related

GSheets GS Dates are one day off for 3/9/2020 - 4/5/2020 all other days are correct

GS code comes back one day off when getting date from 3/9/2020 - 4/5/2020
All dates between 3/9/2020 - 4/5/2020 comeback incorrect.
Google sheet add date column with date 3/9/2020
Add code to gs below
Comes back: Sun Mar 08 2020 23:00:00 GMT-0600 (CST)
3/9/2020
Sun Mar 08 2020 23:00:00 GMT-0600 (CST)
4/5/2020
Sat Apr 04 2020 23:00:00 GMT-0600 (CST)
var data = SpreadsheetApp.getActiveSpreadsheet().getDataRange().getValues();
SpreadsheetApp.getUi().alert(data[0][0]);
Here is the google sheet: link
The dates come back correctly if I format it using GMT.
var formattedDate = Utilities.formatDate(data[0][0], "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
UTC, GMT and Daylight Saving Time
Neither UTC nor GMT ever change for Daylight Saving Time (DST). However, some of the countries that use GMT switch to different time zones during their DST period.
For example, the United Kingdom is not on GMT all year, it uses British Summer Time (BST), which is one hour ahead of GMT, during the summer months.

DateTime value from backend to frontend

I've been struggling for days with some DateTime values.
I have an API backend that uses entity framework and sql server with .netcore.
The big issue when i want to send a datetime from angular to c#
backend. I noticed that Date() in typescript/javascript by default
uses my timezone and i don't know how to exclude it.
For example my date looks like this:
Wed Jul 11 2019 21:00:00 GMT+0300
And when it arrived in c# it becomes 07/10/2010(mm-dd-yyyy), it subtracts 1 day due to timezone.
Is there a way to standardize the Date variable to ignore timezone and always keep the same format DD-MM-YYYY ?
I've also tried to use MomentJS and still can't figure it out, even my MomentJS compares are acting strange due tot his issue.
For example:
const VacationStart = moment(calendarEntity.Vacation.StartTime).utc(false);
const VacationEnd = moment(calendarEntity.Vacation.EndTime).utc(false);
if (VacationStart.isSameOrBefore(ColumnDate,'day') && VacationEnd.isSameOrAfter(ColumnDate,'day')) {
return '#FF0000';
}
In the above example:
VacationStart is Wed Jul 10 2019 21:00:00 GMT+0300
VacationEnd is Wed Jul 17 2019 00:00:00 GMT+0300
ColumnDate is Thu Aug 15 2019 03:00:00 GMT+0300 (incremental value)
Yet for some reason even if i use isSameOrBefore(ColumnDate,'day') to specify to compare only up to days it still does not work. When VacationEnd should be equal to ColumnDate is return false.
Note: everything is in a foreach loop where ColumnDate increases by +1 day.
You just need to use UTC time (Greenwich Mean Time)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC
https://learn.microsoft.com/en-us/dotnet/api/system.datetime.utcnow?view=netcore-2.2
So something like this:
new Date(new Date().toUTCString()); -- "Mon Jul 01 2019 17:55:41 GMT-0700 (Pacific Daylight Time)"
new Date().toUTCString(); -- "Tue, 02 Jul 2019 00:56:38 GMT"
new Date().toString(); -- "Mon Jul 01 2019 17:57:03 GMT-0700 (Pacific Daylight Time)"

Browser shows repeating datetime values after DST change

I am trying to display some datatime values in the a data table, here is the example code
<html>
<head>
<script type="text/javascript">
console.log(new Date(2017,2,26,0,0,0));
console.log(new Date(2017,2,26,1,0,0));
console.log(new Date(2017,2,26,2,0,0));
console.log(new Date(2017,2,26,3,0,0));
</script>
</head>
<body>
</body>
</html>
the browser shows repeating values for 2 AM.
Here is the log output
Sun Mar 26 2017 00:00:00 GMT+0000 (GMT Standard Time)
Sun Mar 26 2017 02:00:00 GMT+0100 (GMT Daylight Time)
Sun Mar 26 2017 02:00:00 GMT+0100 (GMT Daylight Time) **(Should it not be 3am)**
Sun Mar 26 2017 03:00:00 GMT+0100 (GMT Daylight Time) **(Should it not be 4am)**
I know I can use Date.UTC()
console.log(new Date(Date.UTC(2017,2,26,0,0,0)));
console.log(new Date(Date.UTC(2017,2,26,1,0,0)));
console.log(new Date(Date.UTC(2017,2,26,2,0,0)));
console.log(new Date(Date.UTC(2017,2,26,3,0,0)));
But that will display wrong date time values in other time zones.
Can someone suggest a solution to this problem? Or can someone explain what is happening here...?
This behavior depends on where time zone that is currently set on your computer is participating in daylight savings time Does Everyone Observe Daylight Saving Time?
If you switch you locale to Iceland time zone, for instance, (UTC+00:00) Monrovia, Rejkjavik and execute the code in console:
new Date(2017,2,26,0,0,0)
new Date(2017,2,26,1,0,0)
new Date(2017,2,26,2,0,0)
new Date(2017,2,26,3,0,0)
You will see the output where all hours are observed:
Sun Mar 26 2017 00:00:00 GMT+0000 (Greenwich Standard Time)
Sun Mar 26 2017 01:00:00 GMT+0000 (Greenwich Standard Time)
Sun Mar 26 2017 02:00:00 GMT+0000 (Greenwich Standard Time)
Sun Mar 26 2017 03:00:00 GMT+0000 (Greenwich Standard Time)
For countries that do participate in daylight savings one our will be missing depending on their timezone.
You could also check (UTC+10:00) Brisbane, Australia you see that all hours from midnight of 26th to midnight of 27th of March are displayed correctly.
If you can use libraries I highly recomend you to use MomentJS, it will make your life easier.
console.log(moment("2017-02-26 00:00:00").format());
console.log(moment("2017-02-26 01:00:00").format());
console.log(moment("2017-02-26 02:00:00").format());
console.log(moment("2017-02-26 03:00:00").format());

Javascript Date() timezone incosistency

I get inconsistent timezone based on params to Date():
new Date()
Sun Oct 25 2015 18:10:42 GMT+0200 (IST)
new Date(1445720400)
Sat Jan 17 1970 19:35:20 GMT+0200 (IST)
new Date(144572040000)
Thu Aug 01 1974 09:54:00 GMT+0300 (IDT)
new Date(14457204000000)
Thu Feb 17 2428 20:00:00 GMT+0200 (IST)
I tried reading the docs or finding an explanation to this weirdness, but couldn't.
I've checked on both Chrome 46 and Safari 7.1.8,
Any ideas?
Isn't this just daylight savings? One of the dates happened to be in the summer?
The problem in then you set different time in ms as param for 'new Date()'. And you have different time zones because the Date has been generated in different seasons (Summer's time and Winter's time). It is normal.

Date-time stamp conversion in javascript

I have Date String Thu May 23 2013 18:19:32 GMT+0530 (India Standard Time) from my database. I want to make in this format THURSDAY May 23 2013 18:19:32 GMT 0500 CDT in ext-js.any idea ? Thanks in advance.
There are 2 excellent ate parsing libraries available tat you can use. They are both very small
https://code.google.com/p/datejs/
http://momentjs.com/
Sample datejs usage:
Date.parse('Thu, 1 July 2004 22:30:00 GMT') // Thu Jul 01 2004 16:30:00
You can then format the date object in whatever format you require for output.

Categories

Resources