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

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

From source file:Main.java

public static String dateTimeFormat(Date date, int dateFormat, int timeFormat) {
    DateFormat dateFormat1 = DateFormat.getDateTimeInstance(dateFormat, timeFormat);
    return dateFormat1.format(date);
}

From source file:Main.java

public static String get_MdHm_String() {
    Date date = new Date();
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String currenttime = format.format(date);
    return currenttime;
}

From source file:Main.java

public static void printDate(Locale locale, Date date) {
    DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    String formattedDate = formatter.format(date);
    System.out.println("SHORT: " + formattedDate);

    formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
    formattedDate = formatter.format(date);
    System.out.println("MEDIUM: " + formattedDate + "\n");

}

From source file:Main.java

public static String calendarDateForLocale(Calendar calendar, Locale locale) {
    DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    return dateFormatter.format(calendar.getTime());
}

From source file:Main.java

public static String getDateTime(Date spawnDate) {
    DateFormat dateFormat = new SimpleDateFormat("EEE, dd, MMM yyyy hh:mm:ss Z");
    return dateFormat.format(spawnDate);
}

From source file:Main.java

public static String generateFileName(String fileName) {
    DateFormat format = new SimpleDateFormat("yyMMddHHmmss");
    String formatDate = format.format(new Date());
    int random = new Random().nextInt(10000);
    int position = fileName.lastIndexOf(".");
    String extension = fileName.substring(position);

    return formatDate + random + extension;
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
public static String getLongToDate(String time) {

    long foo = Long.parseLong(time);
    Date date = new Date(foo);
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    return (formatter.format(date));
}

From source file:Main.java

public static String convertUnixDateTimeToString(Long unixDateTime) {
    java.util.Date time = new java.util.Date(unixDateTime);
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH);
    return dateFormat.format(time);
}

From source file:Main.java

/**
 * Formats date time structure to the local string
 *
 * @param dateTime Datetime//from  w w  w.  java  2  s . c o m
 * @return Formatted date time in local
 */
public static String formatDateTimeLocal(Date dateTime) {
    DateFormat formatter = SimpleDateFormat.getDateTimeInstance();
    String formatted = formatter.format(dateTime);
    return formatted;
}