Java Timestamp Format getTimestamp(String format)

Here you can find the source of getTimestamp(String format)

Description

Get timestamp.

License

Open Source License

Parameter

Parameter Description
format the format

Return

string

Declaration

public static String getTimestamp(String format) 

Method Source Code

//package com.java2s;
/**/*from  ww  w  . j a  va  2  s .  c o m*/
 * Copyright (c) 2014 Far Eastone Telecommunications Co., Ltd.
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of 
 * Far Eastone Telecommunications Co., Ltd. ("Confidential Information"). 
 * 
 * You shall not disclose such Confidential Information and shall use it 
 * only in accordance with the terms of license agreement you entered
 * into with Far Eastone Telecommunications Co., Ltd.
 */

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

public class Main {
    /**
     * Get timestamp.
     *
     * @param format the format
     * @return string
     */
    public static String getTimestamp(String format) {
        return _datetime(format);
    }

    /**
     * Assign return data format.
     *
     * @param format the format
     * @return string
     */
    private static String _datetime(String format) {
        return _datetime(format, new Date());
    }

    /**
     * Assign return data format.
     *
     * @param format the format
     * @param date the date
     * @return string
     */
    private static String _datetime(String format, Date date) {
        SimpleDateFormat formater = new SimpleDateFormat(format);
        return formater.format(date).toString();
    }

    /**
     * Assign return data format (by Locale).
     *
     * @param format the format
     * @param date the date
     * @param locale the locale
     * @return string
     */
    private static String _datetime(String format, Date date, Locale locale) {
        SimpleDateFormat formater = new SimpleDateFormat(format, locale);
        return formater.format(date).toString();
    }
}

Related

  1. getFormattedTimestamp(File file)
  2. getFormattedTimeStamp(long timestamp, String formatString)
  3. getFullTimestampFormatter(Locale locale)
  4. getTimestamp(boolean useTwentyFourFormat)
  5. getTimeStamp(String format)
  6. getTimestampFormat()
  7. getTimeStampFormat(Date date)
  8. getTimeStampFormat(Date date)
  9. getTimestampFormat(long time)