zoukankan      html  css  js  c++  java
  • android 日期 时间

    /**
    * 给定一个日期型字符串,返回加减n天后的日期型字符串
    *
    * @param basicDate
    * @param nDays
    * @return
    */
    public static String nDaysAfterOneDateString(String basicDate, int nDays) {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Context.getResources().getConfiguration().locale);
    Date tmpDate = null;
    try {
    tmpDate = df.parse(basicDate);
    } catch (Exception e) {
    // 日期型字符串格式错误
    }
    long nDay = (tmpDate.getTime() / (24 * 60 * 60 * 1000) + 1 - nDays)
    * (24 * 60 * 60 * 1000);
    tmpDate.setTime(nDay);

    return df.format(tmpDate);
    }

    /**
    * 返回今天加减n天后的日期型字符串
    *
    * @param nDays
    * @return
    */
    public static String nDaysAftertoday(int nDays) {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Context.getResources().getConfiguration().locale);
    Calendar rightNow = Calendar.getInstance();
    // rightNow.add(Calendar.DAY_OF_MONTH,-1);
    rightNow.add(Calendar.DAY_OF_MONTH, -nDays);
    return df.format(rightNow.getTime());
    }

    /**
    * 返回今天后几个月的日期型字符串

    * @param nDays
    * @return
    */

    public String nDaysAftertoday(int nMonths) {

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", this
    .getResources().getConfiguration().locale);
    Calendar rightNow = Calendar.getInstance();
    // rightNow.add(Calendar.DAY_OF_MONTH,-1);
    rightNow.add(Calendar.MONTH, +nMonths);
    return df.format(rightNow.getTime());
    }

  • 相关阅读:
    01、启动优先和安全设置
    5、bam格式转为bigwig格式
    1、蛋白质二级结构预测方法
    12、IGV-Integrative Genomics Viewer
    docker-compose 工具安装
    docker-compose.yml 语法说明
    docker 镜像和容器的批量清理
    rancher 笔记 之 rancher应用中心
    golang 学习笔记
    docker registry 搭建
  • 原文地址:https://www.cnblogs.com/Cherry-B/p/3790804.html
Copyright © 2011-2022 走看看