dateTimeFormat


Converts a date/time (String) from one format to another.

Parameters


Combine the parameters as a JSON structure as input.

Parameter

Mandatory/Optional

Data Type

Description

inString

Mandatory

String

The date/time to convert.

currentPattern

Mandatory

String

The inString format.

newPattern

Mandatory

String

The format to convert inString to.

locale

Optional

String

Locale for the returned date/time. For example, if locale is EN (English), and pattern is EEE d MMM yyyy, the returned result will be Thu 2000-04-13 01:45:33. If not specified, EN is used by default. The locales currently supported are:
  • EN: English

  • CH: Chinese

lenient

Mandatory

String

Checks the inString value.
  • true:Performs a lenient check. If the inString format does not match the currentPattern format, the date in the currentPattern format will be interpreted and returned. If the interpretation is incorrect, it will return an invalid date.

  • false:Performs a strick check. If the inString format does not match the currentPattern format, an exception will occur.

Return Values

Value

Data Type

Description

value

String

The inString date in the format as per specified in newPattern.

Samples

var format = tools.DateUtil.dateTimeFormat({"inString":"2021-04-01 05:13:02","currentPattern":"yyyy-MM-dd hh:mm:ss","newPattern":"EEE dd MMM YYYY hh:mm:ss","lenient":true,"locale":"EN"});
return tools.resultBuilder.build(true, JSON.stringify(format));


Output

"Thu 01 Apr 2021 05:13:02"