zoukankan      html  css  js  c++  java
  • three months timestamp

    1、有效期三个月

    package com.hengqin.life.idps;
    
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.text.ParseException;
    
    /**
     * @author: ZhenGuangLi
     * @date: 2019/10/16
     * @Description:
     */
    public class uuidTest {
        public static void main(String args[]) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = null;
            try {
                date = sdf.parse("2019-10-23 11:20:00");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.MONTH, -3);
            Date lastDate = calendar.getTime();
            System.out.println("三个月前的日期" + sdf.format(lastDate));
            calendar.setTime(lastDate);
            calendar.add(Calendar.MONTH, 3);
            Date forDate = calendar.getTime();
            System.out.println("三个月后的日期" + sdf.format(forDate));
            int pastTime = Integer.valueOf(String.valueOf(forDate.getTime() / 1000));
            System.out.println(pastTime);
        }
    }
    

    2、日期与时间戳的相互转换

        //日期转换成时间戳
        public   String dateToStamp(Date date){
            long it = date.getTime();
            return String.valueOf(it);
        }
        //时间戳转换成日期
        public  String stampToDate(String s){
            String res;
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            long lt = new Long(s);
            Date date = new Date(lt);
            res = simpleDateFormat.format(date);
            return res;
        }
    缘于生活,而归于工作。本人所书,而意于分享。 如有转载,请注明出处! --活出自己范儿
  • 相关阅读:
    HyperLeger Fabric开发(三)——HyperLeger Fabric架构
    WPF设计の画刷(Brush)
    WPF设计の画刷(Brush)
    WPF设计の画刷(Brush)
    Mina Basics 02-基础
    内置方法
    py-opp 类(class)
    Python 学习目录
    py-函数进阶
    py-函数基础
  • 原文地址:https://www.cnblogs.com/Small-sunshine/p/11725123.html
Copyright © 2011-2022 走看看