Java获取当前时间
来源:互联网 发布:手机淘宝怎么差评不了 编辑:程序博客网 时间:2024/06/08 05:26
//精确时间import java.text.SimpleDateFormat; SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss"); Date curDate = new Date(System.currentTimeMillis());//获取当前时间 String str = formatter.format(curDate);//或者:(精确时间)SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String date = sDateFormat.format(new java.util.Date());//年月SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM");String date=sdf.format(new java.util.Date());//指定时区df=DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.CHINA); System.out.println(df.format(new Date()));