Here you can find the source of checkTimestamp(String sval)
Parameter | Description |
---|---|
sval | String representation of desired Timestamp |
public static Timestamp checkTimestamp(String sval)
//package com.java2s; /*//from www . j ava 2 s . c om * This file is part of wnmsextract. * * wnmsextract is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * wnmsextract is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static final DateFormat ALUDB_DF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); /** * Timestamp type validation and conversion. High overhead but necessary on untrustworty sources * @param sval String representation of desired Timestamp * @return Calendar instance reflecting string interpreted as Timestamp in {@link com.alcatel_lucent.nz.wnmsextract.database.ALUDBUtilities} ALU_DF format */ public static Timestamp checkTimestamp(String sval) { Calendar cal = Calendar.getInstance(); cal.set(2000, 0, 1); Timestamp tval = new Timestamp(cal.getTime().getTime()); try { tval = new Timestamp(ALUDB_DF.parse(sval).getTime()); } catch (ParseException pe) { System.err.println("Timestamp parse exception, def to '2000-01-01' :: " + pe); } catch (NumberFormatException nfe) { System.err.println("Timestamp format exception, def to '2000-01-01' :: " + nfe); } return tval; } }