« UJMLサンプル014:コンポーネントの利用(背景) | メイン | UJMLサンプル016:コンポーネントの利用(リストボックス) »

UJMLサンプル015:コンポーネントの利用(日付時刻)(2006/02/03)

Samples_015_component_datetime例えば、JAVAでは日付を取り扱うために、Calendar/GregorianCalendar/Dateといったクラスが提供されている。標準クラスとして用意されているため誰でも使える。

SDKのcomponentsフォルダにはdatetime.ujmsという「ステートマシーン」のファイルがある。これを活用すれば、日付・時刻の取り扱いがとても楽になるのだ。実はdatetime.ujmlというサンプルがSDK内にあり、この中でdatetime.ujmsをincludeして使用している。datetime.ujmlのソースコードを見ればこのステートマシーンの使い方は十分理解できるが、簡略化のため少しずつ解説する。

まずは、

日付を表示する。

以下はそのソースコード。今日の日付を表示する。

ちなみに"_x_utcCurrentDate()"という関数を使用しているがこれはデバイスからUTC時間の現在の日付を得る関数だ。デバイスによってはUTC時間をサポートしていないものもあるため、本来サポートしているかどうかを調べてから使うべき関数であるが、簡略化のため割愛している。詳しくは言語リファレンス(日本語)を参照

---コード
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ujml PUBLIC "-//UIEVOLUTION//DTD UJML 1.5//EN"
"http://www.uievolution.com/dtd/ujml-1.5.dtd" [
    <!ENTITY TIME_ZONE_OFFSET "8"> 
]>
<ujml>
    <application>
        <state-machines>
            <include file="components/datetime.ujms" state-machine="Date" />
        </state-machines>
        <state-variables>
            <state-var name="sMessage" type="boolean"/>
        </state-variables>
        <variables>
            <var name="mMessage" type="string"/>
        </variables>
        <script>
            Date.setDate(_x_utcCurrentDate(), _msec(), &TIME_ZONE_OFFSET;);

            mMessage = _strcat(Date.getYear(),"/", Date.getMonth(), "/", Date.getDay());
            sMessage = false;
            sMessage = true;
        </script>
        <states>
            <state var="sMessage">
                <transition value="true">
                    <display>
                        <label>
                            <text><eval>mMessage</eval></text>
                            <bg>&_COLOR_WHITE;</bg>
                        </label>
                    </display>
                </transition>
            </state>
        </states>
    </application>
</ujml>

トラックバック

この記事のトラックバックURL:
https://www.typepad.com/services/trackback/6a00d8341c2e2e53ef00e550a95d8a8834

UJMLサンプル015:コンポーネントの利用(日付時刻)を参照しているブログ:

コメント

この記事へのコメントは終了しました。