Here you can find the source of toTimestamp(String yyyymmddhhmmss)
Parameter | Description |
---|---|
yyyymmddhhmmss | ex. "20070101120500" , "20530101120500" |
public static Timestamp toTimestamp(String yyyymmddhhmmss)
//package com.java2s; /*//from www .ja v a 2 s . c om * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.sql.Timestamp; public class Main { /** * @param yyyymmddhhmmss ex. "20070101120500" , "20530101120500" * @return Timestamp */ public static Timestamp toTimestamp(String yyyymmddhhmmss) { if (yyyymmddhhmmss == null) { return null; } String year = yyyymmddhhmmss.substring(0, 4); if (Integer.valueOf(year) > 2400) { year = String.valueOf(Integer.parseInt(year) - 543); } String month = yyyymmddhhmmss.substring(4, 6); String day = yyyymmddhhmmss.substring(6, 8); String hour = ""; String minute = ""; String second = ""; if (yyyymmddhhmmss.length() == 8) { hour = "00"; minute = "00"; second = "00"; } else { hour = yyyymmddhhmmss.substring(8, 10); minute = yyyymmddhhmmss.substring(10, 12); second = yyyymmddhhmmss.substring(12, 14); } return Timestamp.valueOf(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + ".0"); } }