dojo/date/locale::parse()

Converts a properly formatted String to a primitive Date object, using locale-specific settings.

Introduction

By default, this method parses looking for both date and time in the string. Formatting patterns are chosen appropriate to the locale. Different formatting lengths may be chosen, with “full” used by default. Custom patterns may be used or registered with translations using the dojo/date/locale::addCustomFormats() method.

Formatting patterns are implemented using the syntax described at unicode.org. When two digit years are used, a century is chosen according to a sliding window of 80 years before and 20 years after present year, for both yy and yyyy patterns. Dates prior to year 100CE requires strict mode.

Usage

require(["dojo/date/locale"], function(locale){
  // Parse a full date time in the current locale
  locale.parse("Tuesday, 13 January 2010 12:43:06 GMT-0:00");

  // Parse a short date in a specific locale
  locale.parser("13/01/2010", {
    locale: "en-gb",
    formatLength: "short",
    selector: "date"
  });
});

Attributes

Arguments Type Description
value String The string to be parsed into a date
options dojo/date/locale::__FormatOptions? Optional This follows the format options of format()

The function returns a Date object.

Examples

require(["dojo/date/locale", "dojo/dom", "dojo/domReady!"],
function(locale, dom){
  var output = locale.parse("13/01/2010", {
    locale: "en-gb",
    formatLength: "short",
    selector: "date"
  });
  dom.byId("output").innerHTML = output.toUTCString();
});
<strong>Output:</strong>
<div id="output"></div>
Error in the documentation? Can’t find what you are looking for? Let us know!