Example usage for java.text SimpleDateFormat SimpleDateFormat

List of usage examples for java.text SimpleDateFormat SimpleDateFormat

Introduction

In this page you can find the example usage for java.text SimpleDateFormat SimpleDateFormat.

Prototype

public SimpleDateFormat(String pattern) 

Source Link

Document

Constructs a SimpleDateFormat using the given pattern and the default date format symbols for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:Main.java

public static String DateToStr(Date date) {

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String str = format.format(date);
    return str;/*from  www  .j  av a 2s.c  om*/
}

From source file:Main.java

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

From source file:Main.java

public static String dateFormat(Date myDate, String fromatString) {
    return new SimpleDateFormat(fromatString).format(myDate);
}

From source file:Main.java

public static String getCurrentTime() {
    SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
    String date = sDateFormat.format(new Date());
    return date;//from   www  .  j  ava 2  s. c  om
}

From source file:Main.java

public static String format(String format, Date date) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    return sdf.format(date);
}

From source file:Main.java

public static String setTimeClock(long time) {
    SimpleDateFormat format = new SimpleDateFormat("HH:mm");
    String timeDate = format.format(new Date(time));
    return timeDate;
}

From source file:Main.java

public static String getCurrentDate(String format) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    return sdf.format(new Date()).toString();
}

From source file:Main.java

public static long getTwoDay(String sj1, String sj2) {
    SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
    long day = 0;
    try {/*  ww  w. j av  a  2s. c  o m*/
        java.util.Date date = myFormatter.parse(sj1);
        java.util.Date mydate = myFormatter.parse(sj2);
        day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
    } catch (Exception e) {
        return 0;
    }
    return day;
}

From source file:Main.java

public static String date2str(Date date) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String str;//from  w  w w  .  ja  v  a2s. co m
    try {
        str = sdf.format(date);
        return str;
    } catch (Exception e) {
        return "";
    }
}

From source file:Main.java

public static String DataToInt(Date dateImg) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
    String strDate = sdf.format(dateImg);
    String[] strs = strDate.split("/");
    int[] ints = { Integer.parseInt(strs[0]), Integer.parseInt(strs[1]), Integer.parseInt(strs[2]) };
    return ints[0] + "-" + ints[1] + "-" + ints[2];
}