Java Timestamp Parse parseAsCassandraTimestamp(String dateString)

Here you can find the source of parseAsCassandraTimestamp(String dateString)

Description

parse As Cassandra Timestamp

License

Open Source License

Parameter

Parameter Description
dateString a parameter

Exception

Parameter Description
ParseException an exception

Declaration

public static Date parseAsCassandraTimestamp(String dateString) throws ParseException 

Method Source Code

//package com.java2s;

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

import java.util.Date;

public class Main {
    public static final String[] CASSANDRA_TS_PATTERNS = new String[] { "yyyy-mm-dd HH:mm", "yyyy-MM-dd HH:mm:ss",
            "yyyy-MM-dd HH:mmZ", "yyyy-MM-dd HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm", "yyyy-MM-dd'T'HH:mmZ",
            "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd", "yyyy-MM-ddZ" };

    /**//from ww w  .  j a  va2s .com
     * 
     * @param dateString
     * @return
     * @throws ParseException
     */
    public static Date parseAsCassandraTimestamp(String dateString) throws ParseException {
        SimpleDateFormat parser = new SimpleDateFormat();
        parser.setLenient(false);
        for (String pattern : CASSANDRA_TS_PATTERNS) {
            parser.applyPattern(pattern);
            try {
                return parser.parse(dateString);
            } catch (ParseException e) {

            }
        }
        throw new ParseException("Unable to parse as date [" + dateString + "]", -1);
    }
}

Related

  1. parse(java.sql.Timestamp timestamp)
  2. parseDateTimeToTimestamp(String string)
  3. parseHeaderDate(String timestamp)
  4. parseSnapshotTimestamp(final String tstamp)
  5. parseSQLiteTimestamp(String dd)