Example usage for java.text SimpleDateFormat format

List of usage examples for java.text SimpleDateFormat format

Introduction

In this page you can find the example usage for java.text SimpleDateFormat format.

Prototype

public final String format(Date date) 

Source Link

Document

Formats a Date into a date-time string.

Usage

From source file:Main.java

/**
 * long time to string//w ww  .  j  a  va  2 s  . c o m
 *
 * @param timeInMillis
 * @param dateFormat
 * @return
 */
public static String getTime(long timeInMillis, SimpleDateFormat dateFormat) {
    return dateFormat.format(new Date(timeInMillis));
}

From source file:Main.java

/**
 * Convert milliseconds to "yyyy-MM-dd" format string.
 * /*from  ww w  .ja  va  2 s.c  o m*/
 * @param milliseconds Milliseconds.
 * @return Formated string.
 */
public final static String convertDate(long milliseconds) {
    Date date = new Date(milliseconds);
    SimpleDateFormat dateFormate = new SimpleDateFormat("yyyy-MM-dd");
    return dateFormate.format(date);
}

From source file:Main.java

public static String getCurrentTime(String pattern) {

    SimpleDateFormat simpleDate = new SimpleDateFormat(pattern);
    return simpleDate.format(new Date());
}

From source file:Main.java

public static String getCurrTime() {
    Date now = new Date();
    SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    String s = outFormat.format(now);
    return s;/* w  w  w  . jav  a 2  s  . c  om*/
}

From source file:Main.java

public static String getStringTime(Long lon, String model) {
    String re_StrTime = null;//from ww  w  . j a va2 s.c  o  m
    SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(model);
    re_StrTime = mSimpleDateFormat.format(new Date(lon));
    return re_StrTime;
}

From source file:Main.java

public static String timeStampToStr(long timeStamp) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String date = sdf.format(timeStamp * 1000);
    return date;/*  www . j  a  v a2  s. c  o  m*/
}

From source file:Main.java

static String currentDateTime() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd-hh:mm", Locale.US);
    return sdf.format(new Date());
}

From source file:Main.java

public static String getDate() {
    Date date = new Date();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    return simpleDateFormat.format(date);
}

From source file:Main.java

public static String getFormatterDate(long time) {
    Date d = new Date(time);
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    String data = formatter.format(d);
    return data;// w w  w  . j  av a  2s.c om
}

From source file:Main.java

public static String formatDateTime(long d, String fmt) {
    SimpleDateFormat format = new SimpleDateFormat(fmt, Locale.CHINA);
    return format.format(new Date(d));
}