I am feeding the following date value into handlebars (this is ISODate format):
2016-03-04T11:24:25.893Z
However on the webpage the date shows as the following:
Fri Mar 04 2016 12:24:25 GMT+0100 (CET)
How do I keep handlebars from manipulating the date format?
myDateVarWhichIWantToPass.toISOString() then pass it to handlebars.
Related
I'm trying to replace momentjs with luxonjs which is used in mat-datepicker of a reactive form, initially I'm loading the datepicker field with ISO format
'2022-05-10T10:34:31.311-04:00'
for which I used below luxon formatting to save the values
DateTime.fromISO(
this.form?.get('date')?.value
).toISODate();
DateTime.fromISO(this.form?.get('date')?.value)
.plus({ day: 1 })
.toISODate();
When I select different date, the date format is different from my original
Sun May 01 2022 00:00:00 GMT-0400 (Eastern Daylight Time)
How to change this format to ISO using luxon
I solved this issue with a workaround by converting the reactive form date value to ISO format using angular DatePipe
let date = new DatePipe('en-US').transform(
this.form?.get('date')?.value,
'yyyy-MM-ddThh:mm:ss'
);
date = DateTime.fromISO(date).plus({ day: 1 }).toISODate();
I'm trying to make the bootstrap datepicker display the date in UTC instead of in the browser timezone (as it does by default). I read in the docs that I can specify toDisplay and toValue functions and make them customize how the display is done. As I was implementing the toDisplay function, I first set the date in the element like this:
divElement.datepicker('update', new Date(1420066800000));
Then I was debugging toDisplay() and the first step was to check the value of the first parameter of the toDisplay() function, which is a date object, and make sure it has the same value I supplied when setting the date using 'update', but I noticed that it's different and so my question is why is that so?
The value I supplied when using 'update' is 1420066800000 which is printed as "Thu Jan 01 2015 00:00:00 GMT+0100 (CET)" and the value of the date parameter of toDisplay() is printed as "Thu Jan 01 2015 01:00:00 GMT+0100 (CET)".
Thanks.
I get the start date of my calendar like this:
var date_start = $('#calendar').fullCalendar('getView').start
with .toDate() I can see this result in chrome console:
Mon Nov 09 2015 01:00:00 GMT+0100 (ora solare Europa occidentale)
I need to display this result:
Mon Nov 09 2015 00:00:00
I also want get the end of the day, should be this:
Tue Nov 10 2015 00:00:00
How I can achieve this result?
toDate gives you back a JavaScript Date object. Any output string is therefore based on the specific implementation of Date.toString. If you want specific output, you should instead format using moment's format function.
date_start.format("ddd MMM DD YYYY HH:mm:ss")
However, this will return 01:00 and you asked for 00:00. It's not clear if you are asking for the local start-of-day, or if you're asking for the equivalent UTC value.
If you wanted the local start of the day:
date_start.clone().startOf('day').format("ddd MMM DD YYYY HH:mm:ss")
If you wanted the equivalent UTC value:
date_start.clone().utc().format("ddd MMM DD YYYY HH:mm:ss")
Cloning is important, as moment objects are mutable. If you don't clone, then you'll be manipulating the original moment, which could have unintended side effects in fullcalendar. You can use either the clone function shown above, or you can wrap it in the moment function, as in moment(date_start)... Both do the same thing.
For the ending value, looks like you want the start of the next day, so do this:
date_start.clone().startOf('day').add(1, 'day').format("ddd MMM DD YYYY HH:mm:ss")
Or:
date_start.clone().utc().add(1, 'day').format("ddd MMM DD YYYY HH:mm:ss")
Again, pick the one that corresponds to your usage scenario.
FYI - you seem to be asking for UTC, but in the vast majority of cases, local time is more relevant when displaying a calendar such as fullcalendar to a user.
I use DateBox in Google App Script, and got the value of DateBox Sat Jul 20 2013 00:00:00 GMT+0800 (HKT).
How can I convert it to just be 2013-07-20?
Use Utilities.formatDate() function.
I have a client side JavaScript that generates a date in JavaScript( new Date(2007,5,1)).
I need this date passed through to a hidden field that the code behind can access.
My issue is that when the hidden field is converted into a DotNet datetime, the time is incorrect. This is because the JavaScript is including timezone info from the client browser.
DotNet is then using this info to recalculate the time based on the difference between the server time and the client time.
What i need from the JavaScript is just the year, month and day.
I don't want to pass through 3 int values to my code behind as this will be a major change to the whole app.
What is the best way for me to accomplish this?
If i can set a UTC time with no timezone info I think that might work.
Any help is appreciated.
demo
If I understood it correctly,
you need .toDateString()
var date = new Date(2007,5,1);
document.write(date);
document.write("<br><br>versus<br><br>");
document.write(date.toDateString());
prints
Fri Jun 01 2007 00:00:00 GMT+0800 (Taipei Standard Time)
versus
Fri Jun 01 2007
You can use DateTimeOffset.ParseExact to parse a string to a DateTimeOffset value using the format you specify:
string dateString = "Fri Jun 01 2007 00:00:00 GMT+08:00";
DateTimeOffset date = DateTimeOffset.ParseExact(dateString, "ddd MMM dd yyyy hh:mm:ss 'GMT'zzz", CultureInfo.InvariantCulture);
You have to put GMT in quotes otherwise M will be interpreted as a format character.
Unfortunatelly, it is not possible to ignore part of the string value. If your string includes the name of the timezone you have to split it first and get the part without the description
string dateString = "Fri Jun 01 2007 00:00:00 GMT+08:00 (Taipei Standard Time)";
var parts=dateString.Split('(');
string datePart = parts[0].TrimEnd();
var date=DateTimeOffset.ParseExact(datePart,"ddd MMM dd yyyy hh:mm:ss 'GMT'zzz",CultureInfo.InvariantCulture);
You can build up a string from the javascript Date object you have created - it has getDate(), getMonth() and getFullYear() methods that you can use to build up the exact string you want in the hidden field.
I would recommend to use a format specification in C# when you get the values in the code behind file. Let me explain what I mean -
The date time format for the Date(...) in JavaScript is as follows
"Tue Jun 1 11:12:15 UTC+0530 2010"
which in C# would translate to the following format string -
"ddd MMM d hh:mm:ss UTCzzz yyyy"
with this format string use the DateTime.ParseExact(string <Hidden Field Value>, format, provider) to get the correct value for the datetime in C#.
Use provider as System.Globalization.CultureInfo.InvariantCulture.