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