Difference between revisions of "Extensions.DateTime.FormatDate"

From emotive
Jump to navigation Jump to search
Line 10: Line 10:
 
== Description ==
 
== Description ==
 
<!--T:1-->
 
<!--T:1-->
Date format is a term which converts a timestamp in a date format and returns as a string. If there is no formatting specified, is the time to ISO 8601:2004 in the following format:
+
Date format is a term which converts a timestamp in a date format and returns as a string.
<blockquote style="text-align:center;">
+
If no custom format is given, the ISO 8601 conform date output shall be formatted equivalent to the custom pattern:
'''YYYY-MM-DDThh:mm:ss[.fff]+hh:mm''' <br/>
+
<blockquote style="text-align:left;">
(The symbols "-", ".", ":", ",", "+" And "T" are delimiters)
+
'''yyyy-MM-dd'T'HH:mm:ss'.'SSSZ'''
 
</blockquote>
 
</blockquote>
 +
Where "T" is the time designator and "." is a separator for the following millisecond portion. The pattern is language independent. The currently set locale does not influence the output.
 +
 +
{{Warning|Results from FormatDate should be used for user representations only and not for test logic, because ex-changeability is not guaranteed across different run time systems (e.g. ERA, time zone)!}}
 +
 +
{{Note|The format pattern rules are analogous to the rules given for the [https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html class java.text.SimpleDateFormat] as specified by the Java™ 2 Platform Standard Ed. 6.}}
  
 
<!--T:2-->
 
<!--T:2-->
The following table gives an overview of the decoding of the individual format icons.
+
The following table gives an overview of the decoding of the format patterns.
{| style="text-align:center" border="0" cellpadding="5"
+
{| style="text-align:left" border="0" cellpadding="5"
|+ style="color:gray" | <small>Modules of the ISO 8601 time format</small>
+
|+ style="color:gray" | <small>Date format pattern specifiers</small>
 
|- style="background: gray; color: white; vertical-align:top;"  
 
|- style="background: gray; color: white; vertical-align:top;"  
| YYYY || MM || DD || hh || mm || ss || fff || hh || mm
+
| Specifier(s) || Meaning || Presentation || Example
 +
|-
 +
| G || Era || Text (localized) || AD
 +
|-
 +
| yy, yyyy || Year (two digits / four digits) || Number || 11, 2011
 +
|-
 +
| M, MM || Month in year (without / with leading zero) || Number || 9, 09
 +
|-
 +
| MMM, MMMM || Month in year (short form / long form) || Text (localized) || Jan, January
 +
|-
 +
| d, dd || Day in month (without / with leading zero) || Number || 3, 09
 +
|-
 +
| D || Day in year || Number || 304
 +
|-
 +
| F || Day of week of month || Number || 3
 +
|-
 +
| E, EEEE || Day of week (short form / long form) || Text (localized) || Wed, Wednesday
 +
|-
 +
| h, hh || Hours, 1-12 count (without / with leading zero) || Number || 7, 07
 +
|-
 +
| H, HH || Hours, 0-23 count (without / with leading zero) || Number || 7, 07
 +
|-
 +
| m, mm || Minutes (without / with leading zero) || Number || 2, 02
 +
|-
 +
| s, ss || Seconds (without / with leading zero) || Number || 4, 04
 +
|-
 +
| S, SS, SSS || Milliseconds (without / with leading zeros) || Number || 357, 04, 002
 +
|-
 +
| w, W || Week in year / Week in month || Number || 34, 3
 +
|-
 +
| a || AM/PM designator  || Text (localized) || AM
 +
|-
 +
| z, zzzz || Time zone (short form / long form) || Text (localized) || CET, Central European Time
 
|-
 
|-
| Year || Month || Day || Hour || Minute || Second || Milisecond || Hour (difference from GMT) || Minute (difference from GMT)
+
| Z || RFC 822 timezone (timeshift to GMT) || Text || +0100
 
|}
 
|}
  

Revision as of 16:34, 12 July 2019

Classification

Name FormatDate
Short Description Returns a formatted time representation of a timestamp.
Class Term
Extension OTX DateTime Extension
Group -
Exceptions OutOfBoundsException
Checker Rules -
Standard Compliant Yes

OTL Syntax

StringTerm DateTime.FormatDate(IntegerTerm timestamp, StringTerm pattern);

Description

Date format is a term which converts a timestamp in a date format and returns as a string. If no custom format is given, the ISO 8601 conform date output shall be formatted equivalent to the custom pattern:

yyyy-MM-dd'T'HH:mm:ss'.'SSSZ

Where "T" is the time designator and "." is a separator for the following millisecond portion. The pattern is language independent. The currently set locale does not influence the output.

Icons Warning.png Results from FormatDate should be used for user representations only and not for test logic, because ex-changeability is not guaranteed across different run time systems (e.g. ERA, time zone)!

Icons Note.png The format pattern rules are analogous to the rules given for the class java.text.SimpleDateFormat as specified by the Java™ 2 Platform Standard Ed. 6.

The following table gives an overview of the decoding of the format patterns.

Date format pattern specifiers
Specifier(s) Meaning Presentation Example
G Era Text (localized) AD
yy, yyyy Year (two digits / four digits) Number 11, 2011
M, MM Month in year (without / with leading zero) Number 9, 09
MMM, MMMM Month in year (short form / long form) Text (localized) Jan, January
d, dd Day in month (without / with leading zero) Number 3, 09
D Day in year Number 304
F Day of week of month Number 3
E, EEEE Day of week (short form / long form) Text (localized) Wed, Wednesday
h, hh Hours, 1-12 count (without / with leading zero) Number 7, 07
H, HH Hours, 0-23 count (without / with leading zero) Number 7, 07
m, mm Minutes (without / with leading zero) Number 2, 02
s, ss Seconds (without / with leading zero) Number 4, 04
S, SS, SSS Milliseconds (without / with leading zeros) Number 357, 04, 002
w, W Week in year / Week in month Number 34, 3
a AM/PM designator Text (localized) AM
z, zzzz Time zone (short form / long form) Text (localized) CET, Central European Time
Z RFC 822 timezone (timeshift to GMT) Text +0100

If the timestamp value is negative, the OutOfBoundsException exception will be thrown.

Return Value

The Term returns the value, see table below.

Icons Note.png In OTX, Terms are categorized according to its return data type!
Data Type Description
String Date in the form according to ISO8601 or as specified.

Properties

Name Data Type Class Default Cardinality Description
Timestamp Integer Term - [1] This property specifies a date as a time stamp, which is interpreted as the number of milliseconds elapsed since January 1 1970 00:00:00 UTC.
Pattern String Term - [0..1] This feature can represent time in the desired format.

OTL Examples

/// Local Declarations

String CurrentTime;

/// Flow

CurrentTime = DateTime.FormatDate(DateTime.GetTimestamp(), null);

See also

GetTimeStamp
FormatDuration