需要使用 stringTokenizer 格式化给定字符串“18-MAY-92”并获取月份的 int 值
Need format the give string "18-MAY-92" using stringTokenizer and get int value of month
我正在尝试使用字符串分词器格式化作为字符串输入的日期。日期格式将输入为
String str="18-AUG-92".
我把它分成
int ndate = Integer.parseInt(str.nextToken());
int nmonth = Integer.parseInt(str.nextToken());
int nyear = Integer.parseInt(str.nextToken());
但是在 nmonth 期间显示错误,输入的值 "AUG" 在字符串中。
我想将 "AUG" 转换为 08。
有人知道吗?
给你。
String datetime="18-Aug-92";
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd-MMM-yy");
LocalDate date = LocalDate.parse(datetime, dateFormat);
System.out.println(date.getMonth().getValue());
我正在尝试使用字符串分词器格式化作为字符串输入的日期。日期格式将输入为
String str="18-AUG-92".
我把它分成
int ndate = Integer.parseInt(str.nextToken());
int nmonth = Integer.parseInt(str.nextToken());
int nyear = Integer.parseInt(str.nextToken());
但是在 nmonth 期间显示错误,输入的值 "AUG" 在字符串中。
我想将 "AUG" 转换为 08。
有人知道吗?
给你。
String datetime="18-Aug-92";
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd-MMM-yy");
LocalDate date = LocalDate.parse(datetime, dateFormat);
System.out.println(date.getMonth().getValue());