1 /*
2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
347
348 String toDateString() {
349 StringBuffer sb = new StringBuffer();
350 String[] eraNames = null;
351 switch (type) {
352 case GREGORIAN:
353 eraNames = new String[] { "BCE", "" };
354 break;
355
356 case BUDDHIST:
357 eraNames = new String[] { "Before BE", "BE"};
358 break;
359
360 case JAPANESE:
361 eraNames = new String[] {
362 "BeforeMeiji",
363 "Meiji",
364 "Taisho",
365 "Showa",
366 "Heisei",
367 "NewEra"
368 };
369 break;
370 }
371
372 sb.append(eraNames[cal.get(ERA)]);
373 if (sb.length() > 0)
374 sb.append(' ');
375 CalendarUtils.sprintf0d(sb, cal.get(YEAR), 4).append('-');
376 CalendarUtils.sprintf0d(sb, cal.get(MONTH)+1, 2).append('-');
377 CalendarUtils.sprintf0d(sb, cal.get(DAY_OF_MONTH), 2);
378 return sb.toString();
379 }
380
381 String toTimeString() {
382 StringBuffer sb = new StringBuffer();
383 CalendarUtils.sprintf0d(sb, cal.get(HOUR_OF_DAY), 2).append(':');
384 CalendarUtils.sprintf0d(sb, cal.get(MINUTE), 2).append(':');
385 CalendarUtils.sprintf0d(sb, cal.get(SECOND),2 ).append('.');
386 CalendarUtils.sprintf0d(sb, cal.get(MILLISECOND), 3);
387 int zoneOffset = cal.get(ZONE_OFFSET) + cal.get(DST_OFFSET);
|
1 /*
2 * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
347
348 String toDateString() {
349 StringBuffer sb = new StringBuffer();
350 String[] eraNames = null;
351 switch (type) {
352 case GREGORIAN:
353 eraNames = new String[] { "BCE", "" };
354 break;
355
356 case BUDDHIST:
357 eraNames = new String[] { "Before BE", "BE"};
358 break;
359
360 case JAPANESE:
361 eraNames = new String[] {
362 "BeforeMeiji",
363 "Meiji",
364 "Taisho",
365 "Showa",
366 "Heisei",
367 "Reiwa"
368 };
369 break;
370 }
371
372 sb.append(eraNames[cal.get(ERA)]);
373 if (sb.length() > 0)
374 sb.append(' ');
375 CalendarUtils.sprintf0d(sb, cal.get(YEAR), 4).append('-');
376 CalendarUtils.sprintf0d(sb, cal.get(MONTH)+1, 2).append('-');
377 CalendarUtils.sprintf0d(sb, cal.get(DAY_OF_MONTH), 2);
378 return sb.toString();
379 }
380
381 String toTimeString() {
382 StringBuffer sb = new StringBuffer();
383 CalendarUtils.sprintf0d(sb, cal.get(HOUR_OF_DAY), 2).append(':');
384 CalendarUtils.sprintf0d(sb, cal.get(MINUTE), 2).append(':');
385 CalendarUtils.sprintf0d(sb, cal.get(SECOND),2 ).append('.');
386 CalendarUtils.sprintf0d(sb, cal.get(MILLISECOND), 3);
387 int zoneOffset = cal.get(ZONE_OFFSET) + cal.get(DST_OFFSET);
|