Here you can find the source of getTimeStampStringFormat(Timestamp ts, String fmt)
public static String getTimeStampStringFormat(Timestamp ts, String fmt)
//package com.java2s; /**/*from w w w. ja v a2s .c o m*/ * @author David Garratt * * Project Name : Commander4j * * Filename : JUtility.java * * Package Name : com.commander4j.util * * License : GNU General Public License * * This program 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. * * This program 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.commander4j.com/website/license.html. * */ import java.sql.Timestamp; import java.util.LinkedList; public class Main { public static String getTimeStampStringFormat(Timestamp ts, String fmt) { String result = ""; LinkedList<String> fmtList = new LinkedList<String>(); LinkedList<String> valList = new LinkedList<String>(); fmtList.clear(); valList.clear(); result = ts.toString(); fmtList.add("yyyy"); valList.add(result.substring(0, 4)); fmtList.add("yy"); valList.add(result.substring(2, 4)); fmtList.add("mm"); valList.add(result.substring(5, 7)); fmtList.add("dd"); valList.add(result.substring(8, 10)); fmtList.add("hh"); valList.add(result.substring(11, 13)); fmtList.add("mi"); valList.add(result.substring(14, 16)); fmtList.add("ss"); valList.add(result.substring(17, 19)); fmtList.add("yymmdd"); valList.add(result.substring(2, 4) + result.substring(5, 7) + result.substring(8, 10)); int pos = fmtList.indexOf(fmt); if (pos >= 0) { result = valList.get(pos); } else { result = ""; } return result; } }