summaryrefslogtreecommitdiffstats
path: root/src/org/jogamp/jabot/util/TimeTool.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/jogamp/jabot/util/TimeTool.java')
-rw-r--r--src/org/jogamp/jabot/util/TimeTool.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/org/jogamp/jabot/util/TimeTool.java b/src/org/jogamp/jabot/util/TimeTool.java
new file mode 100644
index 0000000..de90361
--- /dev/null
+++ b/src/org/jogamp/jabot/util/TimeTool.java
@@ -0,0 +1,55 @@
+package org.jogamp.jabot.util;
+
+import java.util.Calendar;
+import java.util.TimeZone;
+
+public class TimeTool {
+ public static String UTC_TZ = "UTC";
+ public static String[] ZERO_TZs = { UTC_TZ, "GMT", "GMT0", "Zulu" };
+
+ /** Returns closest to Zulu/UTC TimeZone w/ shortest ID */
+ public static TimeZone getNearZuluTimeZone() {
+ TimeZone tz = null;
+ // Get preferred ..
+ for(int i=0; null == tz && i<ZERO_TZs.length; i++) {
+ tz = TimeZone.getTimeZone(ZERO_TZs[i]);
+ }
+ if(null == tz) {
+ // Get shortest ..
+ final String[] ids = TimeZone.getAvailableIDs(0);
+ if( null != ids && ids.length > 0 ) {
+ int min_len = Integer.MAX_VALUE;
+ int min_idx = -1;
+ for(int i=0; i<ids.length; i++) {
+ final int len = ids[i].length();
+ if( len < min_len ) {
+ min_len = len;
+ min_idx = i;
+ }
+ }
+ tz = TimeZone.getTimeZone(ids[min_idx]);
+ }
+ }
+ if(null == tz) {
+ // last resort - default
+ tz = TimeZone.getDefault();
+ }
+ return tz;
+ }
+
+ /** Returns timestamp of internal Calendar: YYYYMMDD HH:MM:SS (TMZ) */
+ public static String getTimeStamp(final Calendar calendar) {
+ final int year, month, day, hour, minute, seconds;
+ {
+ year = calendar.get(Calendar.YEAR);
+ month = calendar.get(Calendar.MONTH) + 1; // Jan - 1
+ day = calendar.get(Calendar.DAY_OF_MONTH);
+ hour = calendar.get(Calendar.HOUR_OF_DAY);
+ minute = calendar.get(Calendar.MINUTE);
+ seconds = calendar.get(Calendar.SECOND);
+ }
+ return String.format("%04d%02d%02d %02d:%02d:%02d (%s)",
+ year, month, day, hour, minute, seconds, calendar.getTimeZone().getID());
+ }
+
+}