I'm running this code at 9:21am in London UK on Wednesday 10 August.
console.log(moment.tz(date, "America/New_York").startOf("day"), "start!")
console.log(moment.tz(date, timezone).startOf("day"), "timezone current!")
(also ran with dayjs replacing moment, results the same)
the first log returned: Tue Aug 02 2022 01:00:00 GMT+0100 (British Summer Time) {}
the second returned: Wed Aug 03 2022 01:00:00 GMT+0100
The second is correct (mostly), I'd expect 00:00:00but at least the date is right
The time currently in NY is 04:21 so why does it think the current startOf('day') date is yesterday when clearly it's still today?
Related
1) My Accurate date is :Tue Apr 25 2019 00:00:00 GMT+0530
2) But in Calendar when i am selecting time i was get like this
Tue Apr 24 2019 16:56:00 GMT+0530
I was tried to fix below way
moment($scope.ProjectModel.projectStartDate).startOf('day')
But I am getting Tue Apr 24 2019 00:00:00 GMT+0530
This one is not correct, correct date: Tue Apr 25 2019 00:00:00 GMT+0530
So what i need to do to get this date ?
So, it seems like you want to set the date to the start of the next day, rather than the start of the current one. You can do it like this:
moment($scope.ProjectModel.projectStartDate).startOf('day').add(1, 'days');
Or, it seems like you want to round up if the provided date is noon or later, and down otherwise. In this case, just add 12 hours before going to the start of the day:
moment($scope.ProjectModel.projectStartDate).add(12, 'hours').startOf('day');
I'm trying to install V8JS but a timezone test is failing. This test:
https://github.com/phpv8/v8js/blob/php7/tests/timezones.phpt
I followed these instructions https://github.com/phpv8/v8js/blob/php7/README.Linux.md
The issue the test has is that the Date printed is wrong:
================================================================================
001+ string(15) "Europe/Helsinki"
002+ Thu Mar 20 2014 11:03:24 GMT+0200 (Eastern European Standard Time)
003+ string(16) "America/New_York"
004+ Thu Mar 20 2014 11:03:24 GMT+0200 (Eastern European Standard Time)
005+ string(15) "Europe/Helsinki"
006+ Thu Mar 20 2014 11:03:24 GMT+0200 (Eastern European Standard Time)
001- Thu Mar 20 2014 11:03:24 GMT+0200 (EET)
002- Thu Mar 20 2014 05:03:24 GMT-0400 (EDT)
003- Thu Mar 20 2014 11:03:24 GMT+0200 (EET)
================================================================================
The upper 6 Lines are the ACTUAL output. I added a var_dump(getenv('TZ')); to make sure that the timezone is getting changed. The last 3 lines are the expected output. As you can see everything is GMT+0200 which is wrong, only 2 should be +0200
I've checked my php.ini and remove any timezone settings, this did not help at all sadly. Same issue.
Has anyone ever run into something similar? Or Does anyone have an Idea?
I've tried just using V8JS as is, but it crashes sadly.
I compiled a third version of V8 (6.5.143) and this fixed the problem. Not sure why, but atleast the test works now.
I need to convert a String to a Date object.
The date string is delivered in the following format:
"2015-01-28T00:00:00"
When I create a new Date, I get the previous date:
Entered: new Date("2015-01-28T00:00:00")
Result: Tue Jan 27 2015 17:00:00 GMT-0700 (Mountain Standard Time)
Does anyone know why this is occurring?
When you enter the following:
new Date("2015-01-28T00:00:00");
// Result: Tue Jan 27 2015 17:00:00 GMT-0700 (Mountain Standard Time)
the browser assumes that you are giving a date in GMT Time zone. So it will automatically convert the given date to your local date.
It's always a good idea to inform the browser of the timezone you are working on in order to prevent future problems:
new Date("2015-01-28T00:00:00-07:00");
// Result: Tue Jan 28 2015 00:00:00 GMT-0700 (Mountain Standard Time)
Actually, you aren't getting the previous date . . . you are getting that date, offset by the timezone difference.
Tue Jan 27 2015 17:00:00(Mountain Time) + 7 hours (time zone difference) = 2015-01-28T00:00:00 (GMT)
Or, in English, when it is 12:00 Midnight in Greenwich, England, it is 5:00 PM on the previous day in Denver, Colorado. ;)
It's the right date/time, just in a different timezone.
My dev environment is in mac.
I use bootstrap datepicker to choose dates in an application.
When a day like 27/11/2013 is selected in mac when I debug, the screen shows...
day: 1385510400
and the translation to an date object in the same debug tool is,
Wed Nov 27 2013 00:00:00 GMT+0000 (GMT)
which is correct.
All is OK, since here.
I upload the code to a windows environment and open the same page with IE8.
Start the nightmare... :)
In windows, the same day variable is shown like that...
day: 1385506800
and the translation to an date object in the same debug tool is,
Wed Nov 27 2013 00:00:00 GMT+0000 (GMT)
which, is not correct?
If we go to a external tool, the day that gave IE8 is day before, and the translation should be,
Tue, 26 Nov 2013 23:00:00 GMT.
How I can understand this?
There is no relation with the timestamp and the translation to date object, and obviously I can't find a way to make this works in both systems.
Could you wake me up from this nightmare?
Sorry for my english!
Fiddle
In JS in Chrome:
new Date(1385510400000) : Wed Nov 27 2013 01:00:00 GMT+0100
new Date(1385506800000) : Wed Nov 27 2013 00:00:00 GMT+0100
new Date("11/27/2013") : Wed Nov 27 2013 00:00:00 GMT+0100
Please note the order of the date string, it is in US order
Also note the 000 at the end; JS timestamps are in milliseconds
The same in IE8
Wed Nov 27 01:00:00 UTC+0100 2013
Wed Nov 27 00:00:00 UTC+0100 2013
Wed Nov 27 00:00:00 UTC+0100 2013
So exactly the same dates, on hour difference on the first
If you subtract the 1 hour from all dates, you get midnight on the first and 11pm on the 26th on the rest
To normalise you can do
var d = new Date(1385510400000);
d.setHours(0,0,0);
or change to UTC
I found out that on a mac my script is acting different than on a windows. On both systems i am using chrome as the browser, i don't know how to explain my problem properly so ill show you. Below the Javascript function it converts a json time to a javascript date.
function getDateFromJSON(value) {
var retvalue = new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));
return retvalue
}
When i use this function with a json date string on a windows pc as shown bellow the output is: Sat Oct 22 1988 00:00:00 GMT+0200 (W. Europe Daylight Time)
When i use the same function with a mac the output is: Fri Oct 21 1988 23:00:00 GMT+0100 (CEST)
The code i used on both mac and windows is:
console.log(getDateFromJSON("/Date(593474400000)/"));
Can someone please help me explain how i can fix this?
Both dates are the same (after adjusting for timezones)
If you want to standardize, use toUTCString:
> new Date(" Sat Oct 22 1988 00:00:00 GMT+0200 (W. Europe Daylight Time)").toUTCString()
'Fri, 21 Oct 1988 22:00:00 GMT'
> new Date("Fri Oct 21 1988 23:00:00 GMT+0100 (CEST)").toUTCString()
'Fri, 21 Oct 1988 22:00:00 GMT'