formatSpec

Add Visual Format for more information about format specifications.

Specifies a formatting instruction to be used for representing data on the screen.

Type

The formatting instruction is specific to the format type, Date, Number, or Text.

Date

Date masks use the symbols shown below. See Date Format for more examples.

Symbol Description Example

G

Era

AD

y, yyyy

Year

18, 2018

Q, QQQ

Quarter in year

2, 2nd

M, MM, MMM, MMMM

Month in year

2, 02, Feb, February

w

Week number in year

34

W

Week number in month

3

D

Day number in year

200

d, dd

Day number in month

5, 05

u, uu

Day number in week (Monday = 1)

4, 04

F

Day of week in month

2 (i.e., second Tuesday in month)

E, EEEE

Day of week

Wed, Wednesday

a

AM/PM

PM

H

Hour in day (24-hour; midnight is 0)

23, if time is 11:01PM
0, if time is 12:01AM
1, if time is 1:01AM

k

Hour in day (24-hour; midnight is 24)

23, if time is 11:01PM
24, if time is 12:01AM
1, if time is 1:01AM

h

Hour in day (12-hour; midnight is 12)

11, if time is 11:01PM
12, if time is 12:01AM
1, if time is 1:01AM

K

Hour in day (12-hour; midnight is 0)

11, if time is 11:01PM
0, if time is 12:01AM
1, if time is 1:01AM

m, mm

Minute in hour

3, 03

s, ss

Second in minute

9, 09

S, SSS

Millisecond

27, 027

z, zzzz

Time zone

EST, Eastern Standard Time

Z

RFC 822 time zone

-0500

X, XX, XXX

ISO 8601 time zone

-05, -0500, -05:00

Example 1. Date format

For the date Nov 8, 2006:

M = 11;
MM = 11;
MMM = Nov;
MMMM = November
d = 8;
dd = 08;
yy = 06;
yyyy = 2006
EEE = Wed
EEEE = Wednesday

Therefore, mask 'MMM-dd-yyyy' yields “Nov-08-2006.”

Numeric

Numeric masks use the symbols shown below. See Number Format for more examples.

Symbol Description

0

Displays the digit at this location. Displays “0” if there is no value at this location.

#

Displays the digit at this location (rounded, if placed in least significant position to the right of the decimal point). Suppresses display if there is no value at this location.

.

Decimal point

-

Minus sign

,

Grouping separator

E

Separates mantissa and exponent in scientific notation

;

Separates positive and negative sub-patterns

%

Multiplies by 100 and displays as percentage

$, ¥, €, etc.

Inserts the specified currency symbol

¤

Inserts the default currency symbol

Example 2. Number format

For the number 124521.63:

#,###.##  yields 124,521.63
#,###.000 yields 124,521.630

Text

For text formatting, use {0} as a placeholder for the string data.

Example 3. Text format

For the string ‘Susan’:

Salesperson: {0} yields 'Salesperson: Susan'
--{0}-- yields '--Susan--'

Examples

// Date format
format = StyleConstant.DATE_FORMAT;
formatSpec = "MM/dd/yyyy";

// Number format
format = StyleConstant.DECIMAL_FORMAT;
formatSpec = "#,###.00";

// Text format
format = StyleConstant.MESSAGE_FORMAT;
formatSpec = "{0} Inc."

Either syntax below can be used in component script:

formatSpec               // unqualified
Component1.formatSpec    // qualified

For onInit/onRefresh scripts, and for component and property scripts on other components, the second (qualified) form is required.