失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > JAVA输入日期数据类型转换(输入月*日*年 - > 年月日)(SimpleDateFormat)

JAVA输入日期数据类型转换(输入月*日*年 - > 年月日)(SimpleDateFormat)

时间:2019-11-06 01:03:02

相关推荐

JAVA输入日期数据类型转换(输入月*日*年 - > 年月日)(SimpleDateFormat)

public class DateParse {public static void main(String[] args) {Scanner sc = new Scanner(System.in);//输入System.out.println("请输入要转换的数据类型: (格式:年*月*日)");String date = sc.next(); //接收输入的日期格式SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");try {//把接收到的字符串日期转换为日期格式Date parse = sdf.parse(date);//定义需要输出的类型格式SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");String format = sdf1.format(parse);System.out.println(format);} catch (ParseException e) {System.out.println("格式输入错误,请重新输入");e.printStackTrace();}sc.close();}}

如果觉得《JAVA输入日期数据类型转换(输入月*日*年 - > 年月日)(SimpleDateFormat)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。