[Request] custom format-model string for datetime input
format lets us pick any display mode, but we have no way of formating the date in the format-model.
When I create a datetime input that is type="date", the results are:
auto = 2018-05-21T20:00:00.000-04:00 date = Mon May 21 2018 20:00:00 GMT-0400 (EDT) string = 2018-05-21T20:00:00.000-04:00 number = 1526947200000
(not sure why it ends up 8pm my time or may 22nd gmt instead of may 21st 12am)
But this is not a type="datetime", this is a type="date" so I am looking for:
2018-05-21
So an option to format the string type would be nice. Or maybe have "auto" format type="date" as YYYY-MM-DD and type="datetime" format it as YYYY-MM-DDTHH:mm:ss.SSSZ
It is implemented using prop formatModel="string" and you can use a custom format="YYYY/MM/DD"
I stiill have problems with q-datetime
For:
<q-datetime format="YYYY-MM-DD" formatModel="string" type="date"/>
Result is: string = 2018/09/07 00:00:00" It should be string = 2018-09-07
The same issue for type="datetime":
<q-datetime format="YYYY-MM-DD HH:mm:ss" formatModel="string" type="datetime"/>
Result is: string = 2018-09-07T05:24:00.000+02:00" It should be string = 2018-09-07 05:24:00
The model must be a valid, parse-able date-time, so you cannot just store the date part. What the control is taking care of is to provide a cross-browser valid date without time zone, so you can extract later the part you need.
Thank you for the explanation. I've thought about this and you're right. I found a way around this issue with my backend.
OK, so this is a problem. Mainly with this specific statement written above.
What the control is taking care of is to provide a cross-browser valid date without time zone, so you can extract later the part you need.
Here is a single example:
if the value we pass to the datepicker component is '2003-10-21T00:00:00.000+00:00' and the user's timezone is set to any timezone with a negative offset (I did this example having set my system time to New York) then the displayed value will be 2003/10/20 when the format is set to YYYY/MM/DD.
It looks like the component internals are taking this date string, running it through new Date(), that's getting passed through the quasar formatDate function and we end up with the date being displayed as a day earlier having taken the users system timezone offset has been subtracted.
If you want only the date part, timezone agnostic then use as input the data as string in this format: "2003/10/21". If you pass a ISO compliant string you'll get timezone conversion.
The same thing will happen because when that string gets passed to new Date() the time will be set to 00:00 and if the user is in a negative offset timezone the date will be wrong
Can you please try?
Yes I see it does work... We were originally doing this but not in the exact format you have stated
Can you tell me why this one works: 2019/08/27 and this one doesnt: 2019-08-27
Because of some quirk/feature in the specification of js that specifies that the parsing of datetime values from string is done using local timezone when separated with / and as UTC or specified timezone else.
how to add second in text input time ?