import java.util.*;public class Now {public static void main(String arg[]) {
/*
** on some JDK, the default TimeZone is wrong
** we must set the TimeZone manually!!!
** Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("EST"));
*/
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
java.text.SimpleDateFormat sdf =
new java.text.SimpleDateFormat(DATE_FORMAT);
/*
** on some JDK, the default TimeZone is wrong
** we must set the TimeZone manually!!!
** sdf.setTimeZone(TimeZone.getTimeZone("EST"));
*/
sdf.setTimeZone(TimeZone.getDefault());
System.out.println("Now : " + sdf.format(cal.getTime()));
}
}
Here some formatting possibilities available through the SimpleDateFormat class.
Thanks to T. Guirado for the tip. import java.util.*;
import java.text.*;public class ShowToday {
public static void main(String args[]) {
ShowToday st = new ShowToday();
st.demo();
}
public void demo() {
System.out.println(easyDateFormat("dd MMMMM yyyy"));
System.out.println(easyDateFormat("yyyyMMdd"));
System.out.println(easyDateFormat("dd.MM.yy"));
System.out.println(easyDateFormat("MM/dd/yy"));
System.out.println(easyDateFormat("yyyy.MM.dd G 'at' hh:mm:ss z"));
System.out.println(easyDateFormat("EEE, MMM d, ''yy"));
System.out.println(easyDateFormat("h:mm a"));
System.out.println(easyDateFormat("H:mm:ss:SSS"));
System.out.println(easyDateFormat("K:mm a,z"));
System.out.println(easyDateFormat("yyyy.MMMMM.dd GGG hh:mm aaa"));
} public String easyDateFormat (String format) {
Date today = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(format);
String datenewformat = formatter.format(today);
return datenewformat;
}
}
/*
** on some JDK, the default TimeZone is wrong
** we must set the TimeZone manually!!!
** Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("EST"));
*/
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
java.text.SimpleDateFormat sdf =
new java.text.SimpleDateFormat(DATE_FORMAT);
/*
** on some JDK, the default TimeZone is wrong
** we must set the TimeZone manually!!!
** sdf.setTimeZone(TimeZone.getTimeZone("EST"));
*/
sdf.setTimeZone(TimeZone.getDefault());
System.out.println("Now : " + sdf.format(cal.getTime()));
}
}
Here some formatting possibilities available through the SimpleDateFormat class.
Thanks to T. Guirado for the tip. import java.util.*;
import java.text.*;public class ShowToday {
public static void main(String args[]) {
ShowToday st = new ShowToday();
st.demo();
}
public void demo() {
System.out.println(easyDateFormat("dd MMMMM yyyy"));
System.out.println(easyDateFormat("yyyyMMdd"));
System.out.println(easyDateFormat("dd.MM.yy"));
System.out.println(easyDateFormat("MM/dd/yy"));
System.out.println(easyDateFormat("yyyy.MM.dd G 'at' hh:mm:ss z"));
System.out.println(easyDateFormat("EEE, MMM d, ''yy"));
System.out.println(easyDateFormat("h:mm a"));
System.out.println(easyDateFormat("H:mm:ss:SSS"));
System.out.println(easyDateFormat("K:mm a,z"));
System.out.println(easyDateFormat("yyyy.MMMMM.dd GGG hh:mm aaa"));
} public String easyDateFormat (String format) {
Date today = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(format);
String datenewformat = formatter.format(today);
return datenewformat;
}
}
解决方案 »
- mysql JDBC 批量插入大量数据(100w),性能
- 求一个SQL语句
- UDP协议与TCP协议
- eclipse啟動遇到如下問題,幫忙分析下都有哪些原因
- 录音后变声效果是怎么实现的- 男声变女声
- 如何得到某个盘符下如d:\a 下面所有以.gif为扩展名的文件列表???谢谢大家
- 菜鸟必读2:J2SE,J2EE,J2ME有什么意义和区别(欢迎收藏)
- Can an interface name be used as the type of a variable?
- byte, char, shor, int 之间的关系
- 流媒体主要是指什么,各位有什么好的资料吗,谢谢了!
- 高分求解……从数据库取出的中文只有第一个汉字能显示,是什么原因?
- 在java中如何实现打印???
import java.util.*;
Date currentdate=new Date();
http://www.csdn.net/expert/topic/120/120981.shtm