My FNZ Studio Version
The article you are currently reading is not compatible with your selected My Appway version.

Business Objects

Latest Update: 11.02.2022 |
Documentation
10
9
8
7

1 Introduction

Sometimes, you need to show different date formats for different languages. Or maybe you just want a simple way to model dates without writing much code. You can easily do this using Date Formats in Appway.

First, create different Date Format Output Patterns for each language. For this example, I'm going to use the format "long". You need to set the Locale to the proper string (such as "en" for English or "zh" for Chinese; if you want to, you can create more complex Locales using the format <Language>[_<Country>[_<Variant>]]).

Then, access them using the LONG Script Function (if you use a different format than "long", you'll need to use a different Script Function to access the formats - either SHORT or MEDIUM). Here's how that would look:

1 Function PrintDate(Date $date) : String Begin
2    Local String $fdate;
3    $fdate := LONG($date, LANGUAGE());
4    Return $fdate;
5 End

This will format the date properly for each language you've defined as a Format Pattern. It's a very clean solution that requires very little code. Furthermore, it's easy to change formats or add more languages at a later date without changing the code itself.
If you want to know how the patterns themselves look, you can take a look at Sun's documentation. Here's an example for a Chinese pattern that is used for Tempest's site:

1.bmp

This format will render as something like this:

2.bmp

2 US Format Workaround

If you've looked at Sun's documentation, you may have found a problem. It's impossible to have a format that looks like this:

November 16th 2009

The reason is that Java can't automatically generate the "th" string after the day. Here's a workaround that allows you to implement this format. First, create a date format that looks like this:

November 16.... 2009

Not yet quite what we want. We're using the four dots as placeholders for the "th". Finally, change the function to add the missing "th" for English dates, replacing the placeholder dots:

 1 Function PrintDate(Date $date) : String Begin
 2    Local String $fdate;
 3    $fdate := LONG($date, LANGUAGE());
 4    If LANGUAGE() == 'en' Then
 5       Local String $day := DATEFORMAT($date, 'd');
 6       If $day == '1' || $day == '21' || $day == '31' Then
 7          $fdate := REPLACE($fdate, '\\.\\.\\.\\.', 'st');
 8       ElseIf $day == '2' || $day == '22' Then
 9          $fdate := REPLACE($fdate, '\\.\\.\\.\\.', 'nd');
10       ElseIf $day == '3' || $day == '23' Then
11          $fdate := REPLACE($fdate, '\\.\\.\\.\\.', 'rd');
12       Else
13          $fdate := REPLACE($fdate, '\\.\\.\\.\\.', 'th');
14       End
15    End
16    Return $fdate;
17 End

And there you go:

November 16th 2009

© 2026 Appway AG. All Rights Reserved