DateTime.parseString()
Signature
DateTime parseString (String date, String format)
Description
Parses the date
provided in the string according to the format and returns it as a DateTime with default time zone.
Parameters
Name | Type | Description |
date | String | A String containing a date to be parsed. e.g. "03-11-2004 14:59:04".
3 digits millisecond is required if parsing millisecond. i.e. "03-11-2004 14:59:04.250" is correct, "03-11-2004 14:59:04.25" is not valid. |
format | String | A String containing a format describing how the date should be parsed. e.g. "MM-dd-yyyy HH:mm:ss", "MM-dd-yyyy HH:mm:ss.SSS". |
Returns
Type | Description |
DateTime | The result DateTime. |
See Also
java.text.SimpleDateFormat
Example
String result = DateTime.format (DateTime.parseString("03-11-2004 14:59:04.250", "MM-dd-yyyy HH:mm:ss.SSS"), "MM-dd-yyyy HH:mm:ss");
Result is: result contains: "03-11-2004 14:59:04".
Notes: The format pattern is compatible with the one in java.text.SimpleDateFormat. 3 digits millisecond has to be specified
in the date parameter if parsing millisecond.