码迷,mamicode.com
首页 > 其他好文 > 详细

three months timestamp

时间:2019-10-23 12:04:22      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:exce   util   std   last   rip   orm   turn   oid   日期   

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;
    }

three months timestamp

标签:exce   util   std   last   rip   orm   turn   oid   日期   

原文地址:https://www.cnblogs.com/Small-sunshine/p/11725123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!