datetimepicker icon indicating copy to clipboard operation
datetimepicker copied to clipboard

Datetimepicker does not support the standard date/time format (ISO-8601)

Open burnchar opened this issue 10 years ago • 8 comments

Unless there's a feature I am missing, DateTimePicker doesn't support the international standard date/time format ISO-8601, e.g. 1981-01-28T00:00:00

(see http://xkcd.com/1179/ and http://en.wikipedia.org/wiki/ISO_8601 ) Unfortunately this makes it difficult to use when populating with JSON or any other data source that uses the standard format.

Tried:

format: 'Y-m-dTH:i:s'
format: 'Y-m-d\TH:i:s'

(Puts the time zone in place of the T)

format: 'Y-m-d"T"H:i:s'

(Puts the time zone and quotes in place of the T, e.g. 2014-12-13"MST"10:26:00)

format: 'c'

--> From the ISO-8601 option in the PHP date format documentation which is for some reason is linked on the datetimepicker website as the official format documentation (Returns "c")

burnchar avatar Dec 13 '14 17:12 burnchar

+1 on this. For example Angular.js uses ISO8601 everywhere and this is only format for datetime inputs. See https://docs.angularjs.org/api/ng/input/input%5Bdatetime-local%5D for example.

Currently receipt «How to use moment.js with jquery datetimepicker» from docs along with according format settings seems to solve problem for me:

Date.parseDate = function( input, format ){
  return moment(input,format).toDate();
};
Date.prototype.dateFormat = function( format ){
  return moment(this).format(format);
};

element.datetimepicker({
  format:      'YYYY-MM-DDTHH:mm:ssZ',
  formatTime:  'HH:mm',
  formatDate:  'YYYY-MM-DD',
})

But I'm afraid can redefining of Date methods break something or not.

Envek avatar Jan 21 '15 14:01 Envek

You have to double-escape the T (because the format string uses \T, and the backslash itself needs escaping to be embedded in JavaScript. That is, use format: 'Y-m-d\\TH:i:s'.

jonahgreenthal avatar Feb 17 '15 02:02 jonahgreenthal

Hello! Is it possible to show date-time in format Y-m-d H:i, but convert to/form value as Y-m-d\\TH:i:s ?

JavaWebinar avatar Nov 09 '15 23:11 JavaWebinar

So, seeing this issue, can one not submit ISO8601?

I need to show a human-readable format in the input but submit in 8601. Is this not possible?

tBaxter avatar Nov 20 '15 16:11 tBaxter

double escaping does not work, when I use Y-m-d\\TH:i:s I simply get 2016-02-17\PST00:00:00. Seems like an odd oversight not having an ISO8601 compatible format.

HasPhillip avatar Feb 01 '16 18:02 HasPhillip

Y-m-d\\TH:m:s is working fine for me... It renders the correct result: 2016-02-07T22:02:06

captain-theo avatar Feb 05 '16 02:02 captain-theo

@HasPhillip May be you resolved problem already, but anyway it can be helpful for someone. I had the same problem on version 2.4.7, went back on version 2.4.5 - and double escaping works.

Exidnus avatar May 02 '16 12:05 Exidnus

Hey everybody. It was hard, it was about 1 hour, but i have fount the solution. All what you need just add validateOnBlur:false

Timofei725 avatar Dec 11 '22 20:12 Timofei725