zoukankan      html  css  js  c++  java
  • SimpleDateFormat深入使用

    目标: SimpleDateFormat的使用

    做个案例:

    package com.ithei.DateFormatDemo01;
    
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    /**
     * @program: javaDemo01->DateFormat02
     * @description: 深入使用DateFormat
     * @author: 安生
     * @create: 2021-01-22 19:28
     **/
    public class DateFormat02 {
        public static void main(String[] args) throws ParseException {
            //需求 输出 1314-5-17 22:39:57 2天一小时20分3秒
    
            //第一步 肯定先把 1314-5-17 22:39:57 字符串转换成Date日期对象
            String oldTime = "1314-5-17 22:39:57";
            //创建SimpleDateFormat对象  调用parse方法 解析成Date对象
            // 格式要与字符串的完全一致 所以这里Sun公司为了预防万一 给了异常提示
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date d = sdf.parse(oldTime);
    
            //时间毫秒值 计算  日期对象转换成时间毫秒值
            long newTime = d.getTime() + ( 2L*24*60*60 + 1*60*60 + 20*60 + 3 ) * 1000;
    
            //把字符串转换成日期对象 时间毫秒值转换成日期对象
            System.out.println(sdf.format(newTime));
    
    
    
        }
    }
  • 相关阅读:
    手机号码正则表达式
    POJ 3233 Matrix Power Series 矩阵快速幂
    UVA 11468
    UVA 1449
    HDU 2896 病毒侵袭 AC自动机
    HDU 3065 病毒侵袭持续中 AC自动机
    HDU 2222 Keywords Search AC自动机
    POJ 3461 Oulipo KMP模板题
    POJ 1226 Substrings KMP
    UVA 1455 Kingdom 线段树+并查集
  • 原文地址:https://www.cnblogs.com/bichen-01/p/14314998.html
Copyright © 2011-2022 走看看