getServerTimestamp()
API からシステムの現在のタイムスタンプ (協定世界時 (UTC)) を取得します。
構文
1GetServerTimestampResult timestamp = connection.getServerTimestamp();使用方法
API からシステムの現在のタイムスタンプを取得するには、getServerTimestamp() を使用します。たとえば、タイミングまたはデータ同期のために正確なタイムスタンプが必要な場合に実行します。create() または update() でオブジェクトを作成または更新する場合、API はシステムのタイムスタンプを使用してオブジェクトの CreatedDate および LastModifiedDate 項目をそれぞれ更新します。
getServerTimestamp() コールはタイムスタンプを常に協定世界時 (UTC) で返します。ただし、ローカルシステムが、結果をシステムが属するタイムゾーンの設定に基づき自動的に表示してしまうことがあります。
サンプルコード —Java
このサンプルでは、サーバ時間を取得し、ユーザのローカルタイムゾーンでコンソールにそのサーバ時間を書き込みます。
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void doGetServerTimestamp() {
18 try {
19 GetServerTimestampResult result = connection.getServerTimestamp();
20 Calendar serverTime = result.getTimestamp();
21 System.out.println("Server time is: "
22 + serverTime.getTime().toString());
23 } catch (ConnectionException ce) {
24 ce.printStackTrace();
25 }
26}サンプルコード —C#
このサンプルでは、サーバ時間を取得し、ユーザのローカルタイムゾーンでコンソールにそのサーバ時間を書き込みます。
1swfobject.registerObject("clippy.codeblock-2", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void doGetServerTimestamp()
18{
19 try
20 {
21 GetServerTimestampResult result =
22 binding.getServerTimestamp();
23 DateTime serverTime = result.timestamp;
24 Console.WriteLine("Server time is: " +
25 serverTime.ToLocalTime().ToString());
26 }
27 catch (SoapException e)
28 {
29 Console.WriteLine("An unexpected error has occurred: " +
30 e.Message + "\n" + e.StackTrace);
31 }
32}引数
なし。