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

如何用Java编写今天是哪一天?,java,Java,我想把今天写在控制台上。例如,如果今天是星期一,将“星期一”写入控制台。我是Java新手,所以我还没有尝试过任何东西。您可以尝试以下方法: public class GetDayFromDate { public static void main(String[] args) { Date now = new Date(); SimpleDateFormat simpleDateformat = new SimpleDateFormat("E");

我想把今天写在控制台上。例如,如果今天是星期一,将
“星期一”
写入控制台。我是Java新手,所以我还没有尝试过任何东西。

您可以尝试以下方法:

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

    }
}

好的,计划是这样的:你首先尝试编写一个基本的Java程序,阅读/观看一些教程,如果成功了,你应该使用Google来检查这个问题以前是否已经解决,如果是,你可以自己尝试这个解决方案。如果在这一点上,您偶然发现了无法解决的问题,请在StackOverflow上发布带有问题的代码,我们将帮助您解决问题。祝你好运因此,你要做的第一件事就是拿起一本关于Java的书或在线教程。然后你做一些研究。然后你尝试一下。如果你遇到了一个特定的问题,问一下。更多:,强烈建议不要回答将被关闭和删除的问题。首先也是最重要的是,它鼓励像这样的垃圾问题。其次,这是浪费你的时间。(不过,删除了我的dv;这是一个答案。)