日期类Date

//获取自1970年1月1日00时00分00秒000毫秒 到 当前的毫秒数
	//SimpleDateFormatDate
	public static void main(String[] args) {
		long now = System.currentTimeMillis();
		System.out.println(now);//1558485869931
		
		
	}	

日期格式化

public static void main(String[] args) {
	Date nowtime = new Date();
	System.out.println(nowtime);//Wed May 22 08:48:56 CST 2019
	
	//引入格式化日期
	//Date---->String
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss SSS");
	
	//开始格式化(Date ---->String)
	String s = sdf.format(nowtime);
	System.out.println(s);
	
	}
//获取特定的日期
	public static void main(String[] args) throws ParseException {
		String time  = "2008-08-09 08:08:08 008";
		//将String转化为Date
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
		//格式不能随便写
		Date d = sdf.parse(time);
		System.out.println(d);//Sat Aug 09 08:08:08 CST 2008
	}
public static void main(String[] args) {
		Date d1 = new Date(10000000);//是毫秒数
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
		System.out.println(sdf.format(d1));
		
		//获取当前系统前十分钟时间
		Date d2 = new Date(System.currentTimeMillis()-1000*60*10);
		System.out.println(sdf.format(d2));
		
		
	}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值