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 formatDateTime(Context ctx, long dateTime) {
    java.text.DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(ctx);
    java.text.DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(ctx);
    return dateFormat.format(dateTime) + " " + timeFormat.format(dateTime);
}

From source file:Main.java

public static String getGMTDate(Date date) {
    if (date == null) {
        return null;
    }// w  ww .j a  v a 2s .  c  o  m
    DateFormat dateFormat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss 'GMT'", Locale.ENGLISH);
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    String dateStr = dateFormat.format(date);
    return dateStr;
}

From source file:com.tala.enterprise.talabank.commons.DateManager.java

public static Date getDate(String format) throws ParseException {
    DateFormat dateFormat = new SimpleDateFormat(format);
    Date date = new Date();
    //return dateFormat.parse(date.toString());
    return DateUtils.parseDate(dateFormat.format(date), format);
}

From source file:Main.java

/**
 * Formats the given date into a nicer date + time string according to the current locale.
 *
 * @param date Date to format// www .j a va  2 s . com
 * @return Localized, nice version of the given timestamp
 */
public static String formatDate(Date date) {
    if (date == null)
        return "";
    DateFormat targetDateFormat = android.text.format.DateFormat.getMediumDateFormat(context);
    DateFormat targetTimeFormat = android.text.format.DateFormat.getTimeFormat(context);
    return targetDateFormat.format(date) + " " + targetTimeFormat.format(date);
}

From source file:Main.java

/**
 * Get the seven days before date//from w  w w  .j  a v  a 2 s  .  co  m
 * 
 * @return {@link String}
 */

public static String GetDateSevenDaysBack() {
    DateFormat formatter = new SimpleDateFormat("dd_MMM_yyyy");
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, -7);
    return formatter.format(calendar.getTime());

}

From source file:fitnesse.components.Logger.java

private static String format(DateFormat format, Calendar calendar) {
    DateFormat tmpFormat = (DateFormat) format.clone();
    tmpFormat.setTimeZone(calendar.getTimeZone());
    return tmpFormat.format(calendar.getTime());
}

From source file:Main.java

public static String formatDateString(Context context, long time) {
    DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
    DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(context);
    Date date = new Date(time);
    return dateFormat.format(date) + " " + timeFormat.format(date);
}

From source file:Main.java

public static String getTimeFormatNO1(String time) {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    DateFormat wantdf = new SimpleDateFormat("yyyy-MM-dd");
    try {/*  www .  jav  a 2  s  .co  m*/
        Date current = new Date();
        Date tiemBefore = df.parse(time.substring(0, 19).replace("T", " "));
        String str = wantdf.format(tiemBefore);
        return str;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return "null";
}

From source file:DateFormatDemo.java

static public void displayDate(Locale currentLocale) {

    Date today;//from   w  ww.  j ava  2  s . c  o m
    String dateOut;
    DateFormat dateFormatter;

    dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, currentLocale);
    today = new Date();
    dateOut = dateFormatter.format(today);

    System.out.println(dateOut + "   " + currentLocale.toString());
}

From source file:com.taobao.itest.util.DateConverter.java

public static String dateToStr(Date date, String pattern) {
    if (pattern == null) {
        pattern = "yyyy-MM-dd HH:mm:ss.SSS";
    }/*from ww  w.j av  a 2 s  .  c  om*/
    DateFormat ymdhmsFormat = new SimpleDateFormat(pattern);

    return ymdhmsFormat.format(date);
}