There is the following code:
new Date("2000-01-01T18:00:00.000Z")
I got:
Date {Sat Jan 01 2000 21:00:00 GMT+0300 (MSK)}
But I need to get:
Date {Sat Jan 01 2000 18:00:00}
i.e. time without specific timezone. How can I do it? Thanks!
Related
I ran into a problem with a 'time' in JS. So basicaly I'm tring to get a time from databace as a string like 11:00 and 20:30.
With the upcoming function code I convert it to js format:
function getDateFromHours(time) {
time = time.split(':');
let now = new Date();
return new Date(now.getFullYear(), now.getMonth(), now.getDate(), ...time);
}
After all I got this: Mon Nov 09 2020 11:00:00 GMT+0300 and this: Mon Nov 09 2020 20:30:00 GMT+0300
So the first question:
How to compare these times to each other?
How to output every 15 minuties between these two times in concole to make it look like:
Mon Nov 09 2020 11:00:00 GMT+0300
Mon Nov 09 2020 11:15:00 GMT+0300
Mon Nov 09 2020 11:30:00 GMT+0300
etc...
For comparing times, and generating times algorithmically, you're best to work in timestamps. It's just a matter of converting between milliseconds and whatever unit of time you care to think in. You can get the timestamp from a Date object with the getTime method.
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)"
I am using the date input type so users can select dates:
<input type="date" name="start" ng-model="formData.start">
Before the data is sent to the server, I see it as this:
console.log("start: " + $scope.formData.start);
start: Sat Jan 09 2016 00:00:00 GMT +0100 (CET)
In my MySQL database it is saved as this:
2016-01-08 23:00:00
So it seems like there is a difference of 1 hour. The problem is that this hour changes the date from one day to the day before. Is there a way to change this?
The date is correct:
You input Sat Jan 09 2016 00:00:00 GMT +0100 (CET) note the GMT +0100. That indicates that the timezone of this date is one hour off (later).
So without the timezone 2016-01-08 23:00:00 is perfectly correct! (GMT +0)
TLDR: both dates are the same
Example:
var date = new Date("Sat Jan 09 2016 00:00:00 GMT +0100 (CET)")
document.write(date.toUTCString())
I'm loading some dates comming from my database into a HTML table in a string format. The string looks like 31-AUG-13 I'm parsing this string into a date object using the below code:
var paymentDate = $(this).find('td.paymentDate').text();
var test = $.datepicker.parseDate('d-M-y', paymentDate);
Everything is ok so far and I'm getting this date object: Date {Sat Aug 31 2013 00:00:00 GMT+0300 (FLE Standard Time)} But once the year is bigger than 2023. In my case 31-JAN-24 and so on it is turning to 1924 and not 2024, so I'm getting these date objects:
Date {Thu Jan 31 1924 00:00:00 GMT+0200 (FLE Daylight Time)}
Date {Fri Feb 29 1924 00:00:00 GMT+0200 (FLE Daylight Time)}
Date {Mon Mar 31 1924 00:00:00 GMT+0300 (FLE Standard Time)}
Date {Wed Apr 30 1924 00:00:00 GMT+0300 (FLE Standard Time)}
And so on. My question is regarding this strange issue. Is there a way to declare the year range and why it is going back to 1900 in the case when the year is bigger than 2023?
This teaches a lesson always use year in full format same was case with y2k problem. Convert date from database in to yyyy format then use it.
I've got an input date as the following:
Thu May 17 2012 18:00:00 GMT+0100 (BST)
However, with the following :
var dateString = 'hu May 17 2012 18:00:00 GMT+0100 (BST)';
document.write($.format.date(dateString, "ddd MMMM dd, HH:mm"));
The resulting output is 1 hour faster than I'd expect:
Thursday May 17, 18:00
Seems to be ignoring the GMT+0100 (BST) part...
Is there anyway to get it to display as 17:00?
You will have to convert the timezone explicitly. You can create a separate function for it.
Please check this link :
http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/6016329