36 lines
969 B
Java
36 lines
969 B
Java
package meerkat.Registry;
|
|
|
|
import java.sql.Timestamp;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
|
|
/**
|
|
* Created by Vladimir Eliezer Tokarev on 1/15/2016.
|
|
* converts time stamps to strings and the other way
|
|
*/
|
|
public abstract class AccurateTimestamp {
|
|
|
|
private static final String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss.SSS";
|
|
|
|
/**
|
|
* Converts current timestamp to string
|
|
* @return
|
|
*/
|
|
public static String GetCurrentTimestampString(){
|
|
return new SimpleDateFormat(DATE_FORMAT).format(new java.util.Date());
|
|
}
|
|
|
|
/**
|
|
* Convets string timesta,p tp java.sql.timestamp
|
|
* @param timestamp string
|
|
* @return
|
|
* @throws ParseException
|
|
*/
|
|
public static java.sql.Timestamp GetTimestampFromString(String timestamp) throws ParseException {
|
|
Date date = new SimpleDateFormat(DATE_FORMAT).parse(timestamp);
|
|
return new Timestamp(date.getTime());
|
|
}
|
|
|
|
}
|