TimeUtils 幾個常用時間
package com.zncm.easyjava;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TimeUtils {
/**
* @author Dminter
* @Mar 9, 2013 9:46:45 AM
* @TODO
* @param args
*/
public static void main(String[] args) {
Date as = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
String time = matter1.format(as);
System.out.println(time);
System.out.println(getYesterdayDate());
System.out.println(dateToEDate(new Date()));
}
// 昨天
public static String getYesterdayDate() {
return new SimpleDateFormat("yyyy-MM-dd").format(new Date().getTime()
- 24 * 60 * 60 * 1000);
}
// 日期是周幾
public static String dateToEDate(Date date) {
String eDate = "";
SimpleDateFormat dateFm = new SimpleDateFormat("EEEE");
eDate = dateFm.format(date);
return eDate;
}
// 當前日期
public static String getDate() {
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
}
// 日期格式
public static String getDateYDM() {
return new SimpleDateFormat("yyyyMMdd").format(new Date());
}
// 全時間
public static String getTime() {
return new SimpleDateFormat("yyyy-MM-dd HH:ss:mm").format(new Date());
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
public class TimeUtils {
/**
* @author Dminter
* @Mar 9, 2013 9:46:45 AM
* @TODO
* @param args
*/
public static void main(String[] args) {
Date as = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
String time = matter1.format(as);
System.out.println(time);
System.out.println(getYesterdayDate());
System.out.println(dateToEDate(new Date()));
}
// 昨天
public static String getYesterdayDate() {
return new SimpleDateFormat("yyyy-MM-dd").format(new Date().getTime()
- 24 * 60 * 60 * 1000);
}
// 日期是周幾
public static String dateToEDate(Date date) {
String eDate = "";
SimpleDateFormat dateFm = new SimpleDateFormat("EEEE");
eDate = dateFm.format(date);
return eDate;
}
// 當前日期
public static String getDate() {
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
}
// 日期格式
public static String getDateYDM() {
return new SimpleDateFormat("yyyyMMdd").format(new Date());
}
// 全時間
public static String getTime() {
return new SimpleDateFormat("yyyy-MM-dd HH:ss:mm").format(new Date());
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.