Java Timestamp Parse parseTimestamp(final String format, final String time)

Here you can find the source of parseTimestamp(final String format, final String time)

Description

parse Timestamp

License

Apache License

Declaration

@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
    private static long parseTimestamp(final String format,
            final String time) 

Method Source Code

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

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Map;
import java.util.WeakHashMap;

public class Main {
    private static final Map<String, DateFormat> c_formats = new WeakHashMap<String, DateFormat>();

    @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
    private static long parseTimestamp(final String format,
            final String time) {
        try {//from  w w  w. ja v  a2 s.  c  om
            final DateFormat dateFormat = getDateFormat(format);
            synchronized (dateFormat) {
                return dateFormat.parse(time).getTime();
            }
        } catch (final Exception e) {
            return 0;
        }
    }

    private static DateFormat getDateFormat(final String format) {
        synchronized (c_formats) {
            DateFormat dateFormat = c_formats.get(format);
            if (null == dateFormat) {
                dateFormat = new SimpleDateFormat(format);
                c_formats.put(format, dateFormat);
            }
            return dateFormat;
        }
    }
}

Related

  1. parseSnapshotTimestamp(final String tstamp)
  2. parseSQLiteTimestamp(String dd)
  3. parseStopTime(String timestamp, String timezone)
  4. parseTimestamp(Date date)
  5. parseTimestamp(Date date)
  6. parseTimestamp(final String s)
  7. parseTimeStamp(final String... key)
  8. parseTimestamp(Long time, String pattern)
  9. parseTimestamp(Object o)