検索

Java ゾーン ID

Aug 30, 2024 pm 03:50 PM
java

ZoneId は Java のクラスです。 time パッケージは、Instant と LocalDateTime の間の変換に必要なルールを指定するために導入されました。このクラスは ZoneOffset クラスのサブクラスであり、Serializable インターフェイスを実装しているためシリアル化も可能です。このクラスは、UTC/グリニッジからのオフセットのみを格納するために使用される特定の形式を使用します。値ベースのクラスであるため、ID に依存した操作を使用すると、予測できない結果が生じる可能性があります。このクラスは、すべてのローカル日時に対して同じオフセットを使用する固定オフセット ID のほとんどを表します。

無料ソフトウェア開発コースを始めましょう

Web 開発、プログラミング言語、ソフトウェア テスト、その他

Java ZoneId の構文

以下は Java ゾーン ID の構文です:

構文:

public abstract class ZoneId
extends Object
implements Serializable

フィールド: public static Final Map SHORT_IDS – これは、TZDB 2005r 以降に準拠した ID のマッピングで構成される変更不可能なマップです。

この地図は次のとおりです:

  • EST: -05:00
  • HST: -10:00
  • MST: -07:00
  • 行為: オーストラリア/ダーウィン
  • AET: オーストラリア/シドニー
  • AGT: アメリカ/アルゼンチン/ブエノスアイレス
  • アート: アフリカ/カイロ
  • AST: アメリカ/アンカレッジ
  • 賭け: アメリカ/サンパウロ
  • BST: アジア/ダッカ
  • 猫: アフリカ/ハラレ
  • CNT: アメリカ/セントジョンズ
  • CST: アメリカ/シカゴ
  • CTT: アジア/上海
  • 食べる: アフリカ/アディスアベバ
  • ECT: ヨーロッパ/パリ
  • IET: アメリカ/インディアナ/インディアナポリス
  • IST: アジア/コルカタ
  • JST: アジア/東京
  • MIT: パシフィック/アピア
  • NET: アジア/エレバン
  • NST: 太平洋/オークランド
  • PLT: アジア/カラチ
  • PNT: アメリカ/フェニックス
  • PRT: アメリカ/プエルトリコ
  • 太平洋標準時: アメリカ/ロサンゼルス
  • 海面標準時間: 太平洋/ガダルカナル
  • VST: アジア/ホーチミン

Java ZoneId のメソッド

Java ゾーン ID のメソッドを以下に示します:

1. public static ZoneId systemDefault()

この関数は、システムのデフォルトのタイムゾーンを取得するために使用されます。これにより、TimeZone.getDefault() 関数が呼び出され、そのシステムのデフォルトのタイムゾーンの値が取得されます。これは、システムのデフォルトのタイムゾーンに加えられた更新が結果に反映されることを意味します。出力は ZoneID 形式に変換されます。この関数によってスローされる以下の 2 つの例外を処理する必要があります:-

  • DateTimeException: これは、変換されたゾーン ID の形式が無効であることを示します
  • ZoneRulesException: これは、変換されたゾーン領域 ID が見つからないことを示します

コード:

import java.time.ZoneId;
public class Main {
public static void main(String[] args) {
ZoneId zone = ZoneId.systemDefault();
System.out.println("Output of systemDefault()-" +zone);
}
}

出力:

Java ゾーン ID

2. public static Set getAvailableZoneIds()

この関数は、利用可能なすべての地域ベースの ID を返すために使用されます。リストは文字列のセットとして返されます。返された文字列は、Of(String) 関数を使用してゾーン ID の形式に変換できます。 Offset-Id は文字列のセットの結果には含まれません。

コード:

import java.time.ZoneId;
import java.util.*;
public class Main {
public static void main(String[] args) {
Set<string> zoneIds = ZoneId.getAvailableZoneIds();
List<string> zoneList = new ArrayList<string>(zoneIds);
Collections.sort(zoneList);
for (int i = 0; i 
<p><strong>出力:</strong></p>
<p><img  src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/172500421161710.png?x-oss-process=image/resize,p_40" class="lazy" alt="Java ゾーン ID" ></p>
<h4 id="public-static-ZoneId-of-StringzoneId">3. public static ZoneId of(StringzoneId)</h4>
<p>この関数は、関数への出力として文字列として渡された有効な ID の ZoneID または ZoneOffset を返します。 ZoneOffset は、文字列の開始文字 (「Z」、「+」、「-」の場合) に基づいて返されます。返される ZoneID は常に ZoneRules に従います。この変換は、完全な解析アルゴリズムを使用して行われます。引数の形式が不正な場合はDateTimeExceptionがスローされ、リージョンの場合はIDが見つからない場合はZoneRulesExceptionがスローされます。</p>
<p><strong>コード:</strong></p>
<pre class="brush:php;toolbar:false">import java.time.*;
import java.util.*;
import java.time.format.TextStyle;
public class Main {
public static void main(String[] args) {
ZoneId zoneId  = ZoneId.of("Asia/Calcutta");
System.out.println("Output of zoneid obtained using of function: "+ zoneId.normalized());
}
}

出力:

Java ゾーン ID

4. public static ZoneId ofOffset(文字列プレフィックス,ZoneOffsetオフセット)

このメソッドは、プレフィックスとオフセットが引数として渡されるときに、ZoneID を取得するために使用されます。プレフィックスとゼロ以外のオフセット ID を含むゾーン ID が返されます。この場合、プレフィックスは「」ZoneOffset が返されます。

プレフィックスは「GMT」、「UTC」、「UT」、または「」である必要があります。それ以外の場合は、メソッドによって IllegalArgumentException がスローされます。

コード:

import java.time.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
ZoneId zoneId = ZoneId.ofOffset("GMT", ZoneOffset.MAX);
System.out.println("OfOffset on ZoneId: " + zoneId);
}
}

Ouput:

Java ゾーン ID

5. public static ZoneId from(TemporalAccessor temporal)

This method is used to convert a TemporalAccessor, an arbitrary set of date and time, object to an instance of ZoneId. This function works in a similar manner to TemporalQueries.zone() that extracts offset base zone id. Thus this method matches the signature of Temporal Query that is being used via ZoneId::from() function.

Code:

import java.time.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
ZonedDateTime zoneddatetime
= ZonedDateTime.parse("2020-02-25T23:12:31.123+02:00[Europe/Paris]");
ZoneId result = ZoneId.from(zoneddatetime);
System.out.println("Zone Id got from "+ "TemporalAccessor object \n"
+ zoneddatetime + "\nis " + result);
}
}

Output:

Java ゾーン ID

6. public abstract String getId()

This function is used to get a unique time-zone ID for a particular object. The format for an offset-based ID is defined by the getId() method in the Timezone class. The ID given as an output helps to uniquely define the object.

Code:

import java.time.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
ZoneId zoneId  = ZoneId.of("Asia/Calcutta");
System.out.println("Id using getID(): "+ zoneId.getId());
}
}

Output:

Java ゾーン ID

7. public String getDisplayName(TextStyle style,Locale locale)

This method helps to provide the textual representation of the zone. The style required as well as the locale of the output required is given as arguments. And thus, the suitable textual representation of the time-zone id is given as an output. In case no textual representation is present, a complete ID is returned as an output.

Code:

import java.time.*;
import java.util.*;
import java.time.format.TextStyle;
public class Main {
public static void main(String[] args) {
ZoneId zoneId  = ZoneId.of("Asia/Calcutta");
String result = zoneId.getDisplayName(TextStyle.SHORT, Locale.ENGLISH);
System.out.println("Name of ID using getDisplayName(): "+ result);
}
}

Output:

Java ゾーン ID

8. public abstract ZoneRules getRules()

This function is used to retrieve the rules that are applied for the given ID. These rules give an idea about the calculations to be performed as well as the functionality associated with time-zone like finding an offset for an instant. ZoneRulesProvider supplies these rules. An advanced provider can also make a dynamic update to these rules, but the results may change over time in this case. In case no rule is available or the rules of JRE is different from that of time-zone, a call made to this function may lead to ZoneRulesException.

Code:

import java.time.*;
import java.util.*;
import java.time.format.TextStyle;
public class Main {
public static void main(String[] args) {
ZoneId zoneId  = ZoneId.of("Asia/Calcutta");
System.out.println("Rules are: "+ zoneId.getRules());
}
}

Output:

Java ゾーン ID

9. public ZoneId normalized()

This method is used to check if the given zoneID contains a fixed Offset and if yes, a ZOneOffset equal to that fixed offset is returned; otherwise, this is returned. The returned ID will also have ZoneRules similar to the given offset, but the result we get from the getId() function is different from what we get here.

Code:

import java.time.*;
import java.util.*;
import java.time.format.TextStyle;
public class Main {
public static void main(String[] args) {
ZoneId zoneId  = ZoneId.of("Asia/Calcutta");
System.out.println("Normalized Id: "+ zoneId.normalized());
}
}

Output:

Java ゾーン ID

10. public boolean equals(Object obj)

This method helps to compare 2 different times ZoneId objects. This method overrides the equals method in the Object class, which is used to compare value stored in 2 objects. Similarly, here the value of these ZoneID is compared to see if 2 objects are equal or not. And, Accordingly, true and false is returned.

Code:

import java.time.*;
import java.util.*;
import java.time.format.TextStyle;
public class Main {
public static void main(String[] args) {
ZoneId zoneId  = ZoneId.of("Asia/Calcutta");
ZoneId zoneId2 = ZoneId.of("Europe/Paris");
System.out.println("Output of Equals: "+ zoneId.equals(zoneId2));
}
}

Output:

Java ゾーン ID

11. public int hashCode()

This function is used to get the hash code for a particular ZoneID object. This hashcode is returned in int format.

Code:

import java.time.*;
import java.util.*;
import java.time.format.TextStyle;
public class Main {
public static void main(String[] args) {
ZoneId zoneId  = ZoneId.of("Asia/Calcutta");
ZoneId zoneId2 = ZoneId.of("Europe/Paris");
System.out.println("Output of zoneid hashCode: "+ zoneId.hashCode());
System.out.println("Output of zoneid2 hashCode: "+ zoneId2.hashCode());
}
}

Output:

Java ゾーン ID

12. public String toString()

This function is used to get the string representation of the time -zone ID that is stored in the particular Offset ID. This function overrides the method toString() of Object class.

Code:

import java.time.*;
import java.util.*;
import java.time.format.TextStyle;
public class Main {
public static void main(String[] args) {
ZoneId zoneId  = ZoneId.of("Asia/Calcutta");
ZoneId zoneId2 = ZoneId.of("Europe/Paris");
System.out.println("Output of zoneid toString: "+ zoneId.toString());
System.out.println("Output of zoneid2 toString: "+ zoneId2.toString());
}
}

Output:

Java ゾーン ID

Conclusion

ZoneID is a serialized class that is used to store the IDs that identify different ZoneRules that the government frequently updates. Thus at the time of serialization, rules are used instead as they contain the entire data set. Also, calling normalized() on ZoneId returns fixed offset ID in the format of ZoneOffset.

以上がJava ゾーン IDの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
高度なJavaプロジェクト管理、自動化の構築、依存関係の解像度にMavenまたはGradleを使用するにはどうすればよいですか?高度なJavaプロジェクト管理、自動化の構築、依存関係の解像度にMavenまたはGradleを使用するにはどうすればよいですか?Mar 17, 2025 pm 05:46 PM

この記事では、Javaプロジェクト管理、自動化の構築、依存関係の解像度にMavenとGradleを使用して、アプローチと最適化戦略を比較して説明します。

適切なバージョン化と依存関係管理を備えたカスタムJavaライブラリ(JARファイル)を作成および使用するにはどうすればよいですか?適切なバージョン化と依存関係管理を備えたカスタムJavaライブラリ(JARファイル)を作成および使用するにはどうすればよいですか?Mar 17, 2025 pm 05:45 PM

この記事では、MavenやGradleなどのツールを使用して、適切なバージョン化と依存関係管理を使用して、カスタムJavaライブラリ(JARファイル)の作成と使用について説明します。

カフェインやグアバキャッシュなどのライブラリを使用して、Javaアプリケーションにマルチレベルキャッシュを実装するにはどうすればよいですか?カフェインやグアバキャッシュなどのライブラリを使用して、Javaアプリケーションにマルチレベルキャッシュを実装するにはどうすればよいですか?Mar 17, 2025 pm 05:44 PM

この記事では、カフェインとグアバキャッシュを使用してJavaでマルチレベルキャッシュを実装してアプリケーションのパフォーマンスを向上させています。セットアップ、統合、パフォーマンスの利点をカバーし、構成と立ち退きポリシー管理Best Pra

キャッシュや怠zyなロードなどの高度な機能を備えたオブジェクトリレーショナルマッピングにJPA(Java Persistence API)を使用するにはどうすればよいですか?キャッシュや怠zyなロードなどの高度な機能を備えたオブジェクトリレーショナルマッピングにJPA(Java Persistence API)を使用するにはどうすればよいですか?Mar 17, 2025 pm 05:43 PM

この記事では、キャッシュや怠zyなロードなどの高度な機能を備えたオブジェクトリレーショナルマッピングにJPAを使用することについて説明します。潜在的な落とし穴を強調しながら、パフォーマンスを最適化するためのセットアップ、エンティティマッピング、およびベストプラクティスをカバーしています。[159文字]

Javaのクラスロードメカニズムは、さまざまなクラスローダーやその委任モデルを含むどのように機能しますか?Javaのクラスロードメカニズムは、さまざまなクラスローダーやその委任モデルを含むどのように機能しますか?Mar 17, 2025 pm 05:35 PM

Javaのクラスロードには、ブートストラップ、拡張機能、およびアプリケーションクラスローダーを備えた階層システムを使用して、クラスの読み込み、リンク、および初期化が含まれます。親の委任モデルは、コアクラスが最初にロードされ、カスタムクラスのLOAに影響を与えることを保証します

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

AtomエディタMac版ダウンロード

AtomエディタMac版ダウンロード

最も人気のあるオープンソースエディター

PhpStorm Mac バージョン

PhpStorm Mac バージョン

最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)