It is possible to use Intl.DateTimeFormat.prototype.formatToParts()
to get the format of the date without knowing it beforehand.
// should default to toLocaleDateString() format
var formatter = Intl.DateTimeFormat()
// I suggest formatting the timestamp used in
// Go date formatting functions to be able to
// extract the full scope of format rules
var dateFormat = formatter.formatToParts(new Date(1136239445999))
On my machine dateFormat
yields
[
{type: "month", value: "1"},
{type: "literal", value: "/"},
{type: "day", value: "3"},
{type: "literal", value: "/"},
{type: "year", value: "2006"},
]
By iterating over this array it should be feasible to parse a string into parts and then fill them in a Date
object.