JavaScript

StringtoDate Method

Syntax

String.toDate(format)

Arguments

formatstring

The date format.

Returns

valuedate

The value of the formatted string as a date.

Description

Extension to the native string variable to convert a string into a date.

Discussion

The String.toDate method will use the Date.fromFormat to create a date variable.

See Date.toFormat for the format values.

Example

var str = '12/16/2018';
var d = str.toDate('MM/dd/yyyy');
// d = Date(2018,11,16)