教育路上
摘要:java使用Calendar获得当前的日期和时间。以下是我们为大家整理的,相信大家阅读完后肯定有了自己的选择吧。
2021-06-22 09:41刘永莘
import java.util.Calendar; class ACalendar { public static void main(String args[]) { String months[] = {//初始化数组 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; Calendar aCalendar = Calendar.getInstance();//用默认时区得到对象 System.out.print("Date: ");// 显示当前日期 System.out.print(months[aCalendar.get(Calendar.MONTH)]); //使用常数 System.out.print(" " + aCalendar.get(Calendar.DATE) + " "); System.out.println(aCalendar.get(Calendar.YEAR)); System.out.print("Time: ");//显示和时间 System.out.print(aCalendar.get(Calendar.HOUR) + ":");//打印时间 System.out.print(aCalendar.get(Calendar.MINUTE) + ":"); System.out.println(aCalendar.get(Calendar.SECOND)); aCalendar.set(Calendar.HOUR, 10); // 设置时间 aCalendar.set(Calendar.MINUTE, 29); aCalendar.set(Calendar.SECOND, 22); System.out.print("Updated time: ");//显示设置后的时间 System.out.print(aCalendar.get(Calendar.HOUR) + ":");//打印时分秒 System.out.print(aCalendar.get(Calendar.MINUTE) + ":"); System.out.println(aCalendar.get(Calendar.SECOND)); } }
访客的评论 2024/10/04 06:59
文中描述的是准确的吗,如何报名!