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

/**
 * Get the time from milliseconds//from ww  w.  j av  a 2  s .  c o m
 * 
 * @return {@link String}
 */
public static String GetTimeFromMilliseconds() {
    DateFormat formatter = new SimpleDateFormat("HH:mm ss SSS");
    Calendar calendar = Calendar.getInstance();
    return formatter.format(calendar.getTime());

}

From source file:Main.java

public static String getDateTime(Date date, String strFormat) {
    Date currentDate = date;//from  w w  w .j  av  a2  s . c o m
    if (strFormat == null) {
        strFormat = "yyyyMMddHHmmss";
    }
    DateFormat dateFormat = new SimpleDateFormat(strFormat);
    if (currentDate == null) {
        currentDate = new Date();
    }
    return dateFormat.format(currentDate);
}

From source file:Test.java

static void displayLocalizedData(Locale l, long number, Date date) {
    NumberFormat nf = NumberFormat.getInstance(l);
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, l);
    System.out.printf("Locale: %s\nNumber: %s\nDate: %s\n\n", l.getDisplayName(), nf.format(number),
            df.format(date));
}

From source file:com.esofthead.mycollab.common.interceptor.aspect.AuditLogUtil.java

static private String formatDateW3C(Date date) {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    String text = df.format(date);
    return text.substring(0, 22) + ":" + text.substring(22);
}

From source file:Main.java

/**
 * Get time and date without datalogger format
 * //ww  w  .  j  av  a  2  s.  co m
 * @return {@link String}
 */

public static String GetTimeandDateUpdate() {
    DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
    Calendar calendar = Calendar.getInstance();
    return formatter.format(calendar.getTime());

}

From source file:com.intuit.tank.harness.functions.DateFunctions.java

/**
 * Get the current date.//  w  w  w .j a v a  2 s .  c om
 * 
 * #function.date.currentDate.06-01-2011
 * 
 * @param format
 *            The format of the response (MM-dd-yyyy, MMddyyyy, etc)
 * @return The current date
 */
private static String getCurrentDate(@Nullable String format) {
    DateFormat formatter = getFormatter(format);
    return formatter.format(new Date());
}

From source file:Main.java

public static String stringFromDateTime(Date dateTime) throws ParseException {
    String dateTimeString;//from w ww .j a v a2 s . c o m
    DateFormat dateFormatter;

    dateFormatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.getDefault());
    dateTimeString = dateFormatter.format(dateTime);

    return dateTimeString;
}

From source file:Main.java

/**
 * Get time and date//from  ww  w.  j a  va 2 s.  c om
 * 
 * @return {@link String}
 */

public static String GetTimeandDate() {
    DateFormat formatter = new SimpleDateFormat("[dd-MMM-yyyy|HH:mm:ss]");
    Calendar calendar = Calendar.getInstance();
    return formatter.format(calendar.getTime());

}

From source file:com.intuit.tank.harness.functions.DateFunctions.java

/**
 * Get the date x days from now./*from  w w w  .j  av  a  2 s  . c  om*/
 * 
 * e.g. #function.date.addDays.1.MM-dd-yyyy
 * 
 * @param days
 *            The number of days to add (negative number to remove)
 * @param format
 *            The format of the response (MM-dd-yyyy, MMddyyyy, etc)
 * @return The new date
 */
private static String addDays(int days, @Nullable String format) {
    Calendar now = Calendar.getInstance();
    now.add(Calendar.DAY_OF_YEAR, days);
    DateFormat formatter = getFormatter(format);
    return formatter.format(now.getTime());
}

From source file:Main.java

public static String TimeToString(Date d) {
    DateFormat formatter;

    formatter = new SimpleDateFormat("HH-mm");
    formatter.setTimeZone(TimeZone.getTimeZone("EST"));

    String s = new StringBuilder(formatter.format(d)).toString();
    return s;/*from w  w  w  . j a va 2s. co m*/
}