• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!--
2/*
3 * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
4 *
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 *  * Redistributions of source code must retain the above copyright notice,
11 *    this list of conditions and the following disclaimer.
12 *
13 *  * Redistributions in binary form must reproduce the above copyright notice,
14 *    this list of conditions and the following disclaimer in the documentation
15 *    and/or other materials provided with the distribution.
16 *
17 *  * Neither the name of JSR-310 nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 -->
34<body>
35<p>
36Support for calendar systems other than the default ISO.
37</p>
38<p>
39The main API is based around the calendar system defined in ISO-8601.
40This package provides support for alternate systems.
41</p>
42<p>
43The supported calendar systems includes:
44</p>
45<ul>
46    <li>{@linkplain org.threeten.bp.chrono.HijrahChronology Hijrah calendar}</li>
47    <li>{@linkplain org.threeten.bp.chrono.JapaneseChronology Japanese calendar}</li>
48    <li>{@linkplain org.threeten.bp.chrono.MinguoChronology Minguo calendar}</li>
49    <li>{@linkplain org.threeten.bp.chrono.ThaiBuddhistChronology Thai Buddhist calendar}</li>
50</ul>
51<p>
52It is intended that applications use the main API whenever possible, including code to read and write
53from a persistent data store, such as a database, and to send dates and times across a network.
54This package is then used at the user interface level to deal with localized input/output.
55See {@link org.threeten.bp.chrono.ChronoLocalDate ChronoLocalDate} for a full discussion of the issues.
56</p>
57<h3>Example</h3>
58<p>
59This example creates and uses a date in a non-ISO calendar system.
60</p>
61<pre>
62        // Print the Thai Buddhist date
63        ChronoLocalDate now1 = ThaiBuddhistChronology.INSTANCE.now();
64        int day = now1.get(ChronoField.DAY_OF_MONTH);
65        int dow = now1.get(ChronoField.DAY_OF_WEEK);
66        int month = now1.get(ChronoField.MONTH_OF_YEAR);
67        int year = now1.get(ChronoField.YEAR);
68        System.out.printf("  Today is %s %s %d-%s-%d%n", now1.getChronology().getId(),
69                dow, day, month, year);
70
71        // Enumerate the list of available calendars and print today for each
72        Set&lt;String&gt; names = Chronology.getAvailableIds();
73        for (String name : names) {
74            Chronology&lt;?&gt; chrono = Chronology.of(name);
75            ChronoLocalDate&lt;?&gt; date = chrono.now();
76            System.out.printf("   %20s: %s%n", chrono.getId(), date.toString());
77        }
78
79        // Print today's date and the last day of the year for the Thai Buddhist Calendar.
80        ChronoLocalDate first = now1
81                .with(ChronoField.DAY_OF_MONTH, 1)
82                .with(ChronoField.MONTH_OF_YEAR, 1);
83        ChronoLocalDate last = first
84                .plus(1, ChronoUnit.YEARS)
85                .minus(1, ChronoUnit.DAYS);
86        System.out.printf("  %s: 1st of year: %s; end of year: %s%n", last.getChronology().getId(),
87                first, last);
88
89</pre>
90</body>
91