Example usage for java.text SimpleDateFormat format

List of usage examples for java.text SimpleDateFormat format

Introduction

In this page you can find the example usage for java.text SimpleDateFormat 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 getTodayDate() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String date = sdf.format(new Date());
    return date;//  www. j  av  a 2 s.  c o m
}

From source file:Main.java

public static String my_time_in(String target_time_zone, String format) {
    TimeZone tz = TimeZone.getTimeZone(target_time_zone);
    Date date = Calendar.getInstance().getTime();
    SimpleDateFormat date_format_gmt = new SimpleDateFormat(format);
    date_format_gmt.setTimeZone(tz);/*from ww  w . j  a va 2  s  . co  m*/
    return date_format_gmt.format(date);
}

From source file:Main.java

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

From source file:Main.java

public static String GetPostingTime(long milliseconds) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(milliseconds);//from   w w w .  j  a v  a2  s .  co  m
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
    return sdf.format(cal.getTime());
}

From source file:Main.java

static String currentDate() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd", Locale.US);
    return sdf.format(new Date());
}

From source file:Main.java

public static String getCurrentTime() {
    Date date = new Date(System.currentTimeMillis());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return sdf.format(date);
}

From source file:Main.java

public static String getCurrentlyDateTime() {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    return dateFormat.format(new Date());
}

From source file:Main.java

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

From source file:Main.java

public static String getBeforeTodayWithFormat(int gap, String dateFormat) {
    Calendar currentCalendar = Calendar.getInstance();
    currentCalendar.add(Calendar.DATE, gap);

    Date date = currentCalendar.getTime();
    SimpleDateFormat format = new SimpleDateFormat(dateFormat);
    return format.format(date);
}

From source file:Main.java

public static String getFullDate(Date date) {
    String pattern = "EEEE, MMM d, yyyy";
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    return sdf.format(date);
}