diff --git a/voter-registry/src/main/java/meerkat/AccurateTimestamp.java b/voter-registry/src/main/java/meerkat/AccurateTimestamp.java new file mode 100644 index 0000000..aaaac2a --- /dev/null +++ b/voter-registry/src/main/java/meerkat/AccurateTimestamp.java @@ -0,0 +1,35 @@ +package meerkat; + +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 GetCurrentTimestampFromString(String timestamp) throws ParseException { + Date date = new SimpleDateFormat(DATE_FORMAT).parse(timestamp); + return new Timestamp(date.getTime()); + } + +}