Java Timestamp Create getTimeStampStringFormat(Timestamp ts, String fmt)

Here you can find the source of getTimeStampStringFormat(Timestamp ts, String fmt)

Description

get Time Stamp String Format

License

Open Source License

Declaration

public static String getTimeStampStringFormat(Timestamp ts, String fmt) 

Method Source Code

//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;
    }
}

Related

  1. getTimestampMinusDays(Integer days)
  2. getTimestampNullSafe(final Date ts)
  3. getTimestampOrNull(Object dbResult)
  4. getTimeStampString()
  5. getTimestampString(long timeInMillis)
  6. getTimestampToOracle()
  7. getTimestampXDaysFromY(long startTimeInMillis, int daysFromStartDate)
  8. getTimeStrByTimestamp(long timestamp, String tz)
  9. timestamp()