bizzaro33:
「YYYY-MM-DD」と私は、整数の配列に変換したい:私は形式の文字列を持っています
これは私のコードです:
int year, month, day;
Date date = Calendar.getInstance().getTime();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String strDate = dateFormat.format(date);
日付が2017年3月16日であれば例えば、私は私の配列は[2017,3,16]のようになりたいです。
デッドプール :
まず、私が使用することを言うでしょうLOCALDATE、てDateTimeFormatterをからのjava-時 APIおよび使用を中止カレンダーとSimpleDateFormatのレガシー日付クラスを
LocalDate currentDate = LocalDate.now();
String dateString = currentDate.format(DateTimeFormatter.ISO_DATE);
あなたはint配列に日付文字列を変換したい場合は、分割が基づいています-
。
Integer[] array =
Arrays
.stream( dateString.split("-") )
.map( Integer::valueOf )
.toArray( Integer[]::new )
;