請問哪里有問題 在eclipse 上可以運行 提交作業(yè)總是說代碼問題
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class HelloWorld {
? ??
? ? public static void main(String[] args) throws ParseException {
? ? ? ??
// 使用format()方法將日期轉換為指定格式的文本
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日 HH時mm分ss秒");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd HH:mm");
SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
? ? ? ??
// 創(chuàng)建Date對象,表示當前時間
? ? ? ? Date now = new Date();
? ? ? ??
? ? ? ? // 調用format()方法,將日期轉換為字符串并輸出
System.out.println(sdf1.format(now) ? ? ? ? ? ? ? ? ? ? ? ? ?);
System.out.println(sdf2.format(now));
System.out.println(sdf3.format(now));
// 使用parse()方法將文本轉換為日期
String d = "2014-6-1 21:05:36";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
? ? ? ??
? ? ? ? ?// 調用parse()方法,將字符串轉換為日期
Date date = sdf.parse(d);
? ? ? ??
System.out.println(date);
}
}
2017-01-26
imooc網站的編譯器對格式要求比較死板,你試試將【System.out.println(sdf1.format(now) ? ? ? ? ? ? ? ? ? ? ? ? ?);】這里面的空格刪掉,應該就可以通過了
2016-12-23
?Date now = new Date();