我想今天写一天到控制台。例如,如果今天是星期一,请将"Monday"
写入控制台。我是Java的新手,所以我还没有尝试过任何东西。
答案 0 :(得分:-3)
您可以尝试以下内容:
public class GetDayFromDate {
public static void main(String[] args) {
Date now = new Date();
SimpleDateFormat simpleDateformat = new SimpleDateFormat("E"); // the day of the week abbreviated
System.out.println(simpleDateformat.format(now));
simpleDateformat = new SimpleDateFormat("EEEE"); // the day of the week spelled out completely
System.out.println(simpleDateformat.format(now));
Calendar calendar = Calendar.getInstance();
calendar.setTime(now);
System.out.println(calendar.get(Calendar.DAY_OF_WEEK)); // the day of the week in numerical format
}
}