Example usage for java.text DateFormat format

List of usage examples for java.text DateFormat format

Introduction

In this page you can find the example usage for java.text DateFormat 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

/**
 * //from   w  w  w  .j  a va  2 s.com
 * @return
 */
public static String getDateTime() {
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = new Date();
    return dateFormat.format(date);
}

From source file:Main.java

public static String newFileName() {
    Date date = new Date();
    DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd_HH-mm-ss", Locale.getDefault());
    return dateFormat.format(date) + ".jpg";
}

From source file:Main.java

public static String getUserPhoneTimezone() {
    TimeZone timeZone = TimeZone.getDefault();

    timeZone = timeZone.getTimeZone(timeZone.getID());
    Date date = new Date();

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    df.setTimeZone(timeZone);/*  w ww  . jav a  2 s . c  o  m*/

    return df.format(date);
}

From source file:Main.java

public static File saveText(String text) throws IOException {
    File f;/*from w w w . j ava2 s. c o m*/
    String filename;
    if (!isExternalStorageWritable())
        throw new IOException("Storage not available");
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    filename = dateFormat.format(new Date());

    f = new File(getAlbumStorageDir(FOLDER_NAME), "Message " + filename + ".txt");
    FileWriter fw = new FileWriter(f);
    fw.write(text);
    fw.close();
    return f;
}

From source file:Main.java

public static String formatTime(long millisecond) {
    DateFormat format = new SimpleDateFormat("mm:ss");
    format.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
    return format.format(millisecond);
}

From source file:io.cloudslang.content.azure.utils.DateUtilities.java

@NotNull
public static String formatDate(@NotNull final Date date) {
    final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
    return dateFormat.format(date);
}

From source file:Main.java

public static String formatDay(Date input) {
    String result = N_C;/*w w w. j  a  va 2s.  c  o  m*/
    if (input != null) {
        DateFormat outputDF = new SimpleDateFormat(DAY_DATE_FORMAT, Locale.FRENCH);
        result = outputDF.format(input);
    }
    return result;
}

From source file:Main.java

public static String formatHour(Date input) {
    String result = N_C;// w  ww  .  ja v  a2 s.  c o  m
    if (input != null) {
        DateFormat outputDF = new SimpleDateFormat(HOUR_DATE_FORMAT, Locale.FRENCH);
        result = outputDF.format(input);
    }
    return result;
}

From source file:Main.java

/**
 * Formats date//from w w  w.  j  a v  a2  s.  c o  m
 *
 * @param time   Time to format
 * @param locale Locale
 * @return Formatted string
 */
public static String formatDateTime(Date time, Locale locale) {
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, locale);
    return dateFormat.format(time);
}

From source file:Main.java

public static String getCurrentDate() {
    DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd");
    Calendar cal = Calendar.getInstance();
    String currentDate = dateFormat.format(cal.getTime());
    return currentDate;
}