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:DateUtils.java

/**
 * A method to get the current date and time to use in a timestamp
 *
 * @return  a string containing the timestamp
 *///from ww  w. j  a va2 s.c o  m
public static String getCurrentDateAndTime() {

    GregorianCalendar calendar = new GregorianCalendar();
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

    return formatter.format(calendar.getTime());

}

From source file:Main.java

public static File newFile() {
    Date date = new Date();
    DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd_HH-mm-ss", Locale.getDefault());
    String filename = dateFormat.format(date) + ".jpg";
    return new File(
            Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS + "/" + filename);
}

From source file:gov.nih.nci.cadsr.cadsrpasswordchange.core.EmailHelper.java

public static String handleExpiryDateToken(String originalText, Date expiryDate) {
    String ret = originalText;//from w w  w . j  a v a  2 s  .  c om
    DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
    String fDate = formatter.format(expiryDate);

    if (originalText != null) {
        ret = StringUtils.replace(originalText, Constants.EMAIL_EXPIRY_DATE_TOKEN, fDate);
    }

    return ret;
}

From source file:Main.java

public static String getTime(long date) {
    final String timeFormatString = "h:mm ";
    DateFormat df = new SimpleDateFormat(timeFormatString, Locale.getDefault());
    Date d = new Date(date);
    return df.format(d);
}

From source file:Main.java

public static String getStringDateFromTimeStamp(long timeStamp, String format) {
    // "ddd MM, yyyy"

    DateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
    Date netDate = (new Date(timeStamp * 1000));

    return sdf.format(netDate);
}

From source file:Main.java

public static String getTime() {
    DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date(System.currentTimeMillis());
    String time = df.format(date);
    return time;//from www .jav  a2s  .  c  o  m
}

From source file:ru.mystamps.web.controller.SitemapController.java

private static String createLastModEntry(DateFormat dateFormatter, SitemapInfoDto item) {
    return dateFormatter.format(item.getUpdatedAt());
}

From source file:Main.java

public static String DateMessage(Date d, Context c) {
    DateFormat df = DateFormat.getDateTimeInstance();
    DateFormat dfS = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    DateFormat dfM = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    DateFormat dfL = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    DateFormat dfF = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

    DateFormat dfNoTime = DateFormat.getDateInstance();
    DateFormat dfSNoTime = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH);
    DateFormat dfMNoTime = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);
    DateFormat dfLNoTime = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
    DateFormat dfFNoTime = DateFormat.getDateInstance(DateFormat.FULL, Locale.ENGLISH);
    DateFormat dfDevice = android.text.format.DateFormat.getDateFormat(c);

    String s = dfDevice.format(d) + " or \n" + dfS.format(d) + " or \n" + dfM.format(d) + " or \n"
            + dfL.format(d) + " or \n" + dfF.format(d);

    return s;/*  w w w . j a va 2  s  . c  om*/

}

From source file:Main.java

public static String getCurrentDateTime() {
    DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd HHmmss");
    Calendar cal = Calendar.getInstance();
    String currentDateTime = dateFormat.format(cal.getTime());
    return currentDateTime;
}

From source file:Main.java

public static String getWeekDay(Date date) {
    DateFormat df = new SimpleDateFormat(weekDayString, Locale.UK);
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    return df.format(date);
}