Help us understand the problem. What is going on with this article?

DateTimeFormatterなんか使い方間違ってる??

More than 3 years have passed since last update.
groovy> import java.time.LocalDate; 
groovy> import java.time.ZoneId; 
groovy> import java.time.format.DateTimeFormatter; 
groovy> def date = LocalDate.of(2015,12,29) 
groovy> println date 
groovy> date.format(DateTimeFormatter.ofPattern("YYYY.MM", Locale.getDefault())) 

2015-12-29
Result: 2016.12

2015.12って表示してほしいんだけど。。。

追記)わかった。。。

https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

大文字のYはその週が何年かってのを出すらしい。

date.format(DateTimeFormatter.ofPattern("YYYY.MM", Locale.getDefault()))
date.format(DateTimeFormatter.ofPattern("yyyy.MM", Locale.getDefault()))
aya_eiya
主要な開発言語は軒並み扱えるオールラウンドプログラマです。サーバーサイドの仕事が多いですが、最近はFlutterとかやってます。
http://aya-eiya.hateblo.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away