Java Timestamp Parse parseTimestamp(String s)

Here you can find the source of parseTimestamp(String s)

Description

parse Timestamp

License

BSD License

Declaration

public static Timestamp parseTimestamp(String s) 

Method Source Code


//package com.java2s;
//License from project: BSD License 

import java.sql.Timestamp;

public class Main {
    public static Timestamp parseTimestamp(String s) {
        Timestamp value;/*from   w  w w.  j a  v  a2s  . c o m*/
        if (s.indexOf(':') > 0) {
            value = Timestamp.valueOf(s);
        } else if (s.indexOf('.') >= 0) {
            // it's a float
            value = new Timestamp((long) ((double) (Double.parseDouble(s) * 1000)));
        } else {
            // integer 
            value = new Timestamp(Long.parseLong(s) * 1000);
        }
        return value;
    }

    public static long parseLong(String s) {
        if (isHex(s)) {
            return Long.parseLong(s.substring(2), 16);
        } else {
            return Long.parseLong(s);
        }
    }

    public static boolean isHex(String s) {
        return s.startsWith("0x") || s.startsWith("0X");
    }
}

Related

  1. parseTimestamp(String d)
  2. parseTimestamp(String date)
  3. parseTimestamp(String dateStr, String format)
  4. parseTimestamp(String dateString)
  5. parseTimestamp(String pattern, String dateTime)
  6. parseTimestamp(String s)
  7. parseTimestamp(String sDate, String sFormat)
  8. parseTimestamp(String src, String pattern)
  9. parseTimestamp(String strDate)