Java获取年月日的两种方式

方式一:

Calendar calendar = Calendar.getInstance();
System.out.println(calendar.get(Calendar.YEAR));
System.out.println(calendar.get(Calendar.MONTH+1));
System.out.println(calendar.get(Calendar.DATE));
方式二:

String[] strNow = new SimpleDateFormat("yyyy-MM-dd").format(new Date()).toString().split("-");
Integer year = Integer.parseInt(strNow[0]);
Integer month = Integer.parseInt(strNow[1]);
Integer day = Integer.parseInt(strNow[2]);

js方式:

var now = new Date();
year = now.getFullYear();
month = now.getMonth()+1;
var day = now.getDate();




阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页