format.parse(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Parses a value from the appropriate preference format to its raw value. The appropriate preference format is the one selected in the Date Format field at Home > Set Preferences.

For a datetime or datetimetz value, use this method to convert a Date Object into a string based on the specified timezone.

Note:

This method is overloaded when you format a datetime or datetimetz value.

Returns

Datetime or datetimetz values are returned as a Date Object.

Note:

If the value given is not valid or parsable, the original value passed to options.value is returned.

Note:

For client scripts, the string returned is based on the user’s system time. For server scripts, the string returned is based on the current time in the Pacific Time Zone. Daylight Savings Time does apply.

Supported Script Types

Client and server scripts

For more information, see SuiteScript 2.x Script Types

Governance

None

Module

N/format Module

Since

2015.2

Parameters

This method is overloaded when you format a datetime or datetimetz value.

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.value

string

required

The input data to parse.

2015.2

options.type

string

required

The field type (for example, DATE, CURRENCY, INTEGER).

Set using the format.Type enum.

2015.2

The table below applies to datetime and datetimeTZ values only.

Parameter

Type

Required / Optional

Description

Since

options.value

string

required

The string that contains the date and time information in the specified timezone.

2015.2

options.type

string

required

The field type (either DATETIME or DATETIMETZ).

Set using the format.Type enum.

2015.2

options.timezone

enum

optional

The time zone represented by the options.value string. Set using the format.Timezone enum.

If a time zone is not specified, the time zone is based on user preference.

If the time zone is invalid, the time zone is set to GMT.

2015.2

Syntax
Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/format Module Script Samples.

          // Add additional code
...
    function(format){
         function parseToValue() {
              // Assume number format is 1.000.000,00 and negative format is -100
              var formattedNum = "-20.000,25"
              return format.parse({value:formattedNum, type: format.Type.FLOAT})
              }
         var rawNum = parseToValue(); // -20000.25 -- a number 
...
// Add additional code 

        

Related Topics

N/format Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices