00001
00010
package org.nees.daq;
00011
00012
import java.util.*;
00013
00016
00017 public class ISOtoRbnbTime {
00018
public static boolean DEBUG =
false;
00019
private int year;
00020
private int month;
00021
private int day;
00022
private int hour;
00023
private int min;
00024
private int sec;
00025
private int frac;
00026
private String ISOString;
00027
private double convertedTStamp;
00028
public boolean is_valid;
00029
00030
00031
00032
00033
00034
public ISOtoRbnbTime(String ISOString)
00035 {
00036 is_valid =
false;
00037
this.ISOString = ISOString;
00038 convert(ISOString);
00039 }
00040
00046
private void convert(String ISOString) {
00047
00048 StringTokenizer st =
new StringTokenizer(ISOString,
"-T:\t\n. ");
00049
try
00050 {
00051 year = Integer.parseInt(st.nextToken());
00052 month = Integer.parseInt(st.nextToken());
00053 day = Integer.parseInt(st.nextToken());
00054 hour = Integer.parseInt(st.nextToken());
00055 min = Integer.parseInt(st.nextToken());
00056 sec = Integer.parseInt(st.nextToken());
00057 is_valid =
true;
00058 }
catch (Exception ignore) {}
00059
00060
00061 frac = 0;
00062
try
00063 {
00064 frac = Integer.parseInt(st.nextToken());
00065 }
catch (Exception ignore) {}
00066
00067
00068
if (year > 1900) year -= 1900;
00069 month -= 1;
00070 convertedTStamp = (
double)(Date.UTC(year,month,day,hour,min,sec)/1000.0);
00071 convertedTStamp += (
double)(frac/100000.0);
00072
if (DEBUG) debugPrint();
00073 }
00074
00075
00076
00077
00078
00079
public double getValue() {
00080
return(convertedTStamp);
00081 }
00082
00083
public void debugPrint()
00084 {
00085 System.out.println(
"Debug print of ISOString " + ISOString);
00086 System.out.println(
" Parsed into " + year +
"." + month +
"." + day +
"." + hour +
"." + min +
"." + sec +
"." + frac);
00087 System.out.println(
" Converted timestamp = " + convertedTStamp);
00088
long milliseconds = (
long) (convertedTStamp*1000.);
00089 Date date =
new Date(milliseconds);
00090 java.text.SimpleDateFormat format =
new
00091 java.text.SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss.SSS");
00092 System.out.println(
" Confirm Date/Time: " + format.format(date) +
"\n");
00093 }
00094 }
00095