zoukankan      html  css  js  c++  java
  • Java获取当前时间年月日、时间格式化打印、字符串转日期

    package com.sysc.simple;
    
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    
    public class DateUtils {
    	
    	public static void show() throws ParseException {
    		//获取当前日期
    		Calendar now = Calendar.getInstance();  
    		int year = now.get(Calendar.YEAR);
    		int month = now.get(Calendar.MONTH) + 1;//注意月份
    		int day = now.get(Calendar.DAY_OF_MONTH);
    		int hour = now.get(Calendar.HOUR_OF_DAY);
    		int minute = now.get(Calendar.MINUTE);
    		int second = now.get(Calendar.SECOND);
    		long millis = now.getTimeInMillis();
            System.out.println(now.getTime());  
            System.out.println(year + month + day + hour + minute + second + millis);
      
            //日期格式化打印
            Date d = new Date();  
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
            String dateNowStr = sdf.format(d);  
            System.out.println("格式化后的日期:" + dateNowStr);  
            
            //字符串解析为日期
            String str = "2014-9-1 13:08:28";  
            Date today = sdf.parse(str);  
            System.out.println("字符串转成日期:" + today);  
    	}
    
    }
    

      

  • 相关阅读:
    204. 计数质数
    面试题 16.06. 最小差
    8. ubantu系统相关
    7. 理论
    6. 图像处理
    5.git
    4.Torch量化
    3.Torch优化工具
    2.DB算法及代码问题分析
    1. 显卡相关问题
  • 原文地址:https://www.cnblogs.com/tq03/p/3955890.html
Copyright © 2011-2022 走看看