Here you can find the source of stringToTimestamp(String marcTimestamp)
Parameter | Description |
---|---|
marcTimestamp | The input timestamp string |
Parameter | Description |
---|---|
ParseException | an exception |
public static Timestamp stringToTimestamp(String marcTimestamp) throws ParseException
//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; } }