如题所述
é£æ¯é»è®¤æ ¼å¼
public class Test{
public static void main(String []args){
Date d = new Date();
String s;
/** Dateç±»çæ ¼å¼: Sat Apr 16 13:17:29 CST 2006 */
System.out.println(d);
System.out.println("******************************************");
/** getDateInstance() */
/** è¾åºæ ¼å¼: 2006-4-16 */
s = DateFormat.getDateInstance().format(d);
System.out.println(s);
/** è¾åºæ ¼å¼: 2006-4-16 */
s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(d);
System.out.println(s);
/** è¾åºæ ¼å¼: 2006å¹´4æ16æ¥ ææå */
s = DateFormat.getDateInstance(DateFormat.FULL).format(d);
System.out.println(s);
/** è¾åºæ ¼å¼: 2006-4-16 */
s = DateFormat.getDateInstance(DateFormat.MEDIUM).format(d);
System.out.println(s);
/** è¾åºæ ¼å¼: 06-4-16 */
s = DateFormat.getDateInstance(DateFormat.SHORT).format(d);
System.out.println(s);
/** è¾åºæ ¼å¼: 2006-01-01 00:00:00 */
java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
s = format1.format(new Date());
System.out.println(s);
/** è¾åºæ ¼å¼: 2006-01-01 01:00:00 */
System.out.println((new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(new Date()));
/** è¾åºæ ¼å¼: 2006-01-01 13:00:00 */
System.out.println((new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
/** è¾åºæ ¼å¼: 20060101000000***/
java.text.DateFormat format2 = new java.text.SimpleDateFormat("yyyyMMddhhmmss");
s = format2.format(new Date());
System.out.println(s);
}
}
è¡¥å ä¸ä¸ï¼
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
System.out.println("System Date: " + cal.get(Calendar.MONTH+1));
注æä¸ï¼æ份æ¯ä»0å¼å§çï¼è¦Calendar.MONTH+1æå¯ä»¥ç追é®
public class Test{
public static void main(String []args){
Date d = new Date();
String s;
/** Dateç±»çæ ¼å¼: Sat Apr 16 13:17:29 CST 2006 */
System.out.println(d);
System.out.println("******************************************");
/** getDateInstance() */
/** è¾åºæ ¼å¼: 2006-4-16 */
s = DateFormat.getDateInstance().format(d);
System.out.println(s);
/** è¾åºæ ¼å¼: 2006-4-16 */
s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(d);
System.out.println(s);
/** è¾åºæ ¼å¼: 2006å¹´4æ16æ¥ ææå */
s = DateFormat.getDateInstance(DateFormat.FULL).format(d);
System.out.println(s);
/** è¾åºæ ¼å¼: 2006-4-16 */
s = DateFormat.getDateInstance(DateFormat.MEDIUM).format(d);
System.out.println(s);
/** è¾åºæ ¼å¼: 06-4-16 */
s = DateFormat.getDateInstance(DateFormat.SHORT).format(d);
System.out.println(s);
/** è¾åºæ ¼å¼: 2006-01-01 00:00:00 */
java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
s = format1.format(new Date());
System.out.println(s);
/** è¾åºæ ¼å¼: 2006-01-01 01:00:00 */
System.out.println((new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(new Date()));
/** è¾åºæ ¼å¼: 2006-01-01 13:00:00 */
System.out.println((new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
/** è¾åºæ ¼å¼: 20060101000000***/
java.text.DateFormat format2 = new java.text.SimpleDateFormat("yyyyMMddhhmmss");
s = format2.format(new Date());
System.out.println(s);
}
}
è¡¥å ä¸ä¸ï¼
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
System.out.println("System Date: " + cal.get(Calendar.MONTH+1));
注æä¸ï¼æ份æ¯ä»0å¼å§çï¼è¦Calendar.MONTH+1æå¯ä»¥ç追é®
谢谢
温馨提示:答案为网友推荐,仅供参考
第1个回答 2015-12-05
是的,这是计算机的时间,如果要格式化,可以通过 java.text.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");来格式化
String time = sdf.format(date);本回答被提问者和网友采纳
String time = sdf.format(date);本回答被提问者和网友采纳