如何用Java编写今天的哪一天?

时间:2015-06-29 07:35:05

标签: java

我想今天写一天到控制台。例如,如果今天是星期一,请将"Monday"写入控制台。我是Java的新手,所以我还没有尝试过任何东西。

1 个答案:

答案 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

    }
}