In the last couple major versions of Chrome, you can display a date input field with a value formatted to the user's locale, like so:
<input type="date" value="2012-11-20">
On Mac OS X, with United States set as my region (with the default date formats), Chrome shows me this:
Is there any way to access the displayed string in JavaScript? (This answer refers to it as the presentation format.) Properties and methods like input.value
and input.valueAsDate.toLocaleDateString()
give me the same date in various formats, but none of them quite match the presentation format.
Here's a fiddle with some of my attempts: http://jsfiddle.net/peterjmag/7KSbA/2/. With Chrome 23 on my Mac, it gives me the following output:
[11/20/12]
input.value
2012-11-20
input.valueAsDate
Mon Nov 19 2012 17:00:00 GMT-0700 (MST)
input.valueAsDate.toDateString()
Mon Nov 19 2012
input.valueAsDate.toLocaleDateString()
Monday, November 19, 2012
input.valueAsDate.toISOString()
2012-11-20T00:00:00.000Z
EDIT: Here's a similar question that makes me think it's not possible (without defining a method to reformat the string, that is).