General Reference



Chapter 2   Formatting Patterns and Styles

Formatting patterns and styles are special characters used to format a Java object as a String. This chapter describes how to use formatting patterns and styles in SilverStream. It is organized as follows:

About formatting patterns and styles   Top of page

In SilverStream you can an use formatting patterns and styles in the following contexts:

Programming Editor

Formatting patterns and styles can be used with the various versions of AgFormat.format(), and are based on Java standards.

    For more information, see the on-line help page for AgFormat.

Expression Editor

Formatting patterns and styles can also be used in the SilverStream Expression Editor with the format() and parse() functions.

    For information about SilverStream expressions, see Expressions, Operators, and Built-in Functions.

Page and Form Designers

Formatting patterns and styles in the Property Inspector for controls that display numeric and date data. You can specify the patterns or select styles from a drop-down list in the Display Format property.

Date and time patterns   Top of page

Both the format and parse functions use dates and times in a locale-specific way. For dates and timestamps that occur prior to 1970, you must be sure to enter the value using the ANSI SQL standard format, which is YYYY-MM-DD HH:MM:SS. You can include a nanosecond value using the .FFFF format, but it is optional. Date and time patterns are made up of the following characters (case is important).

Character

Meaning

Example

Sample Output

a

12 hour clock. Either AM or PM.

a

PM

d

Day in month as a number. d by itself shows the day with not leading 0. dd shows the day with a leading 0 if the date is less than 10 (04).

dd

16

D

Day in year as a number.

DDD

127

E

Day in week.

EEE

Monday

F

Day in week in month.

FF

3 (3rd Tuesday in September)

G

Era designator

G

AD

h

hour in am/pm (1-12)

hh:

05:

H

Hour in day as a number (1-23)

H

2

k

Hour in day as a number (1-24)

kk

23

K

Hour in AM/PM as a number (1-12)

KK

0

m

Minute in hour as a number.

mm:

53:

M

Month in year as number with no leading 0. MM displays the month with a leading 0 if it is less than 10 (i.e., 09). MMM displays the three letter abbreviation of the month (SEP). MMMM displays the full name of the month.

MMM

MM

SEP

09

n

nano seconds

s

Seconds in minute as a number

ss

16

S

milliseconds as a number

SSS

978

w

week in year as a number

ww

30

W

week in month as number.

W

3

u

Forces Greenwich Mean Time

u

GMT time format

y

Year as a number. yy displays the last two digits of the year. yyyy displays all four digits for the year.

YYYY

1997

z

timezone

z

Pacific Standard Time

@

Escape character for text

at

at

'

Single quote

O'Clock

O'Clock

Rules for date and time patterns   Top of page

The number of pattern letters determines the format, as described below.

When working with text

for four or more characters, JDK uses the FULL style. For less than four characters JDK uses the SHORT style. (For examples of the FULL and SHORT styles see the section on "Time and timestamp values").

When working with numbers

JDK uses the minimum number of digits. Shorter numbers are zero-padded to this amount. This is true for all numbers except year numbers which are handled differently. If the number of pattern characters in a year is 2, the year is truncated to 2 digits.

When working with numbers and text

JDK assumes it is text if there are three or more pattern characters, otherwise it is displayed as a number.

Quoted text

Any pattern characters that are not in the ranges of ['a'..'z'] and ['A'..'Z'] are treated as quoted text. For example, characters: colon (:) , period (.),and pound sign appear in the time text even though they are not enclosed in single quotes.

Date and time pattern examples    Top of page

This table shows typical formats for dates, times, and timestamps.

Pattern examples

Output examples

"yyyy.MM.dd G 'at' hh:mm:ss z"

1997.08.10 AD at 11:18:56 GMT

"EEE, MMM d, ''yy"

Mon, June 09, '97

"h:mm a"

2:08 PM

hh 'O''''Clock' a, zzzz

08 O'Clock PM, Greenwich MeanTime

"K:mm a, z"

0:00 PM, GMT

'yyyyy.MMMMM.dd GGG hh:mm aaa'

1997.August.08 AD 11:08 PM

Date and time styles   Top of page

The following table shows examples of using built-in patterns to specify format styles for dates and times. The column labeled Style represents the style name that appears in the SilverStream Designer property sheet.

NOTE   The Style name cannot be used when writing expressions in the Expression Editor. When specifying a style name in the Programming Editor, prepend the class name to the style name. For example: AgFormat.SHORT.

Object Type

Style

Built-in patterns

Example output

Time

FULL

"h:mm:ss a zz"

8:20:20 PM PST

Time

SHORT

"h:mm a"

2:08 PM

Time

LONG

"hh:mm:ss a zz"

8:20:20 PM PST

Time

MEDIUM

"hh:mm:ss a"

8:20:20 PM

Date

SHORT

"m/d/yy"

9/9/92

Date

LONG

"MMM dd,yyyy"

January 1, 1992

Date

MEDIUM

"MMM dd, yyyy"

Jan 1, 1992

TimeStamp

FULL

"EEE, MMM dd, yyyy h:mm:ss a z"

Wednesday, January 01, 1992 4:09:04 AM PST

TimeStamp

SHORT

"m/d/yy h:mm a"

2/1/92 4:04 AM

TimeStamp

LONG

"EEE MM, yyyy h:mm:ss a z"

February 01, 1992 4:04:04: AM PST

TimeStamp

MEDIUM

"MMM dd, yyyy h:mm:ss a"

Jan 1, 1992 4:04:04 AM

Numeric patterns   Top of page

You can create numeric patterns using a string of the characters listed in the following table.

Character

Meaning

#

Indicates a digit. Zeroes show as absent.

0

Indicates a digit. Zeroes appear as 0.

, (comma)

Indicates the locale-specific grouping separator.

-

Indicates the locale-specific negative prefix.

%

Shows the value as a percentage

;

Separates a positive number format that appears on the left from an optional negative number format that appears on the right.

' (single quote)

Used to set off a reserved character so that it appears as a literal in the output.

other

Appears literally in the output.

Numeric styles   Top of page

Numeric objects can be specified as one of the formats shown in the following table. The results shown in the following table were computed using 200.5 as the input.

NOTE   The Style name name cannot be used when writing expressions in the Expression Editor: You must specify the pattern. When specifying a style name in the Programming Editor, prepend the class name to the style name. For example: AgFormat.CURRENCYSTYLE.

Style

Example

Built-in pattern

CURRENCYSTYLE

$200.50

$###.00

NUMBERSTYLE

200.5

###.0

PERCENTSTYLE

20,050%

##,###%






Copyright © 2000, SilverStream Software, Inc. All rights reserved.