Java Timestamp Parse parseTimestamp(Object o)

Here you can find the source of parseTimestamp(Object o)

Description

parse Timestamp

License

Open Source License

Parameter

Parameter Description
o A timestamp string as 'HH:mm:ss' or 'HH:mm'.

Return

Epoch time or 0 if there is a problem parsing the timestamp string.

Declaration

public static long parseTimestamp(Object o) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {
    /**/*from   www  .  j a v  a2  s  .c  o m*/
     * @param o A timestamp string as 'HH:mm:ss' or 'HH:mm'.
     * @return Epoch time or 0 if there is a problem parsing the timestamp string.
     */
    public static long parseTimestamp(Object o) {
        String timestamp = o.toString();
        SimpleDateFormat sdf;
        if (timestamp.length() == 8) {
            sdf = new SimpleDateFormat("HH:mm:ss");
        } else if (timestamp.length() == 5) {
            sdf = new SimpleDateFormat("HH:mm");
        } else {
            return (0L);
        }
        try {
            return (sdf.parse(timestamp).getTime());
        } catch (ParseException e) {
            return (0L);
        }
    }
}

Related

  1. parseTimestamp(Date date)
  2. parseTimestamp(final String format, final String time)
  3. parseTimestamp(final String s)
  4. parseTimeStamp(final String... key)
  5. parseTimestamp(Long time, String pattern)
  6. parseTimestamp(String d)
  7. parseTimestamp(String date)
  8. parseTimestamp(String dateStr, String format)
  9. parseTimestamp(String dateString)