www.mjjq.net > jAvA中怎么得到当前时间的小时

jAvA中怎么得到当前时间的小时

Date date=new Date();DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String time=format.format(date); 不同的方法介绍如下: 1、通过Date类来获取当前时间。 Date day=new Date() SimpleDateFormat df = new SimpleDateForm...

Calendar c = Calendar.getInstance();//可以对每个时间域单独修改 int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int date = c.get(Calendar.DATE); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Cale...

Date date=new Date(); DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time=format.format(date);

获取当前详细时间如下: Date date =new Date(); SimpleDateFormat sdf =new SimpleDateFormat("HH:mm:ss");//只有时分秒 //SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//完整的时间 String time=sdf.format(date);

Calendar calendar = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); calendar.add(Calendar.DAY_OF_YEAR, 1); Date date = calendar.getTime(); System.out.println(sdf.format(date));

Calendar calendar = Calendar.getInstance(); /* HOUR_OF_DAY 指示一天中的小时 */ calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Syste...

一. 获取当前系统时间和日期并格式化输出: import java.util.Date; import java.text.SimpleDateFormat; public class NowString { public static void main(String[] args) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss...

试试, Format f = new SimpleDateFormat("yyyy-MM"); Calendar c = Calendar.getInstance(); System.out.println("之前:" + f.format(c.getTime())); c.add(Calendar.YEAR, -4); System.out.println("之后:" + f.format(c.getTime())); 结果: 之...

给时间加个格式: Date date =new Date(System.currentTimeMillis()); SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss "); String time = formatter.format(date); System.out.println(time); 这样你要取整的话 , ...

一、步骤如下: long currentTime = System.currentTimeMillis() + 30 * 60 * 1000; Date date = new Date(currentTime); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String nowTime="";nowTime= df.format(date);System.out...

网站地图

All rights reserved Powered by www.mjjq.net

copyright ©right 2010-2021。
www.mjjq.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com