Java Timestamp Parse stringToTimestamp(String marcTimestamp)

Here you can find the source of stringToTimestamp(String marcTimestamp)

Description

Convert string in format "yyyyMMddhhmmss.S" (as in the MARC records) to java.sql.Timestamp

License

Open Source License

Parameter

Parameter Description
marcTimestamp The input timestamp string

Exception

Parameter Description
ParseException an exception

Return

The resulting Timestamp object

Declaration

public static Timestamp stringToTimestamp(String marcTimestamp) throws ParseException 

Method Source Code

//package com.java2s;
/**/*from   w w  w  .j  a v a 2s .co  m*/
  * Copyright (c) 2009 University of Rochester
  *
  * This program is free software; you can redistribute it and/or modify it under the terms of the MIT/X11 license. The text of the  
  * license can be found at http://www.opensource.org/licenses/mit-license.php and copy of the license can be found on the project
  * website http://www.extensiblecatalog.org/. 
  *
  */

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /** 
     * Convert string in format "yyyyMMddhhmmss.S" (as in the MARC records)
     * to java.sql.Timestamp 
     * @param marcTimestamp The input timestamp string
     * @return The resulting Timestamp object
     * @throws ParseException
     */
    public static Timestamp stringToTimestamp(String marcTimestamp) throws ParseException {
        Timestamp timestamp;
        Date d = new SimpleDateFormat("yyyyMMddHHmmss.S").parse(marcTimestamp);
        timestamp = new Timestamp(d.getTime());
        timestamp.setNanos(Integer.parseInt(marcTimestamp.substring(marcTimestamp.length() - 1)));
        return timestamp;
    }
}

Related

  1. stringToTimestamp()
  2. stringToTimestamp(final String dateString)
  3. stringToTimestamp(String aS_Timestamp, String aS_Format, Timestamp aTs_ValidStart, Timestamp aTs_ValidEnd)
  4. stringToTimestamp(String date, String formatStr)
  5. stringToTimeStamp(String dateTimeString, String dateTimeFormat, TimeZone tz, Locale locale)
  6. stringToTimestamp(String sTimestamp)
  7. stringToTimestamp(String ts)
  8. stringToTimestamp(String value)
  9. stringToTimesTamp(String yMd, boolean isEndTime)