Convert day of the year to a date in java

后端 未结 2 1690
天涯浪人
天涯浪人 2020-12-12 00:17

I have a number of day of the year. (Today\'s number of the day is 308.) I want to convert this number to a date in SQL format (YYYY/MM/DD). Can I do it in java

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 00:58

    int dayOfYear = 112;
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_YEAR, dayOfYear);
    SimpleDateFormat sdf = new SimpleDateFormat("YYYY/MM/dd");
    System.out.println("Day of year " + dayOfYear + " = " + sdf.format(calendar.getTime()));
    

    hope above snippets helps you

提交回复
热议问题