1. 2016/11/24

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date; /**
* 需求2014-01-01之前的月不变,年份改成2017; 2014-01-01之后的月不变,年份改成+3
*/
public class CalendarTest {
public static void main(String[] args) throws Exception {
System.out.println(formatCraftDate("2015-05-04")); //May 2018
System.out.println(formatCraftDate("2011-05-04")); //May 2017
} private static String formatCraftDate(String dateStr) throws Exception{
String resultDateStr = null;
String stardardDateStr = "2014-01-01";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date stardardDate = dateFormat.parse(stardardDateStr);
Date date = dateFormat.parse(dateStr); //传过来的日期
Calendar calendar = Calendar.getInstance();
if (date.before(stardardDate)) { // 2013-01-01 before 2014-01-01 为true, 月份不变,年统统改成2017
calendar.setTime(date);
resultDateStr = convertMonth(calendar.get(Calendar.MONTH)) + " 2017";
} else { // 2017-01-01 before 2014-01-01 为false , 月份不变,年份加+3
calendar.setTime(date);
calendar.add(Calendar.YEAR, 3);
resultDateStr = convertMonth(calendar.get(Calendar.MONTH)) +" " + calendar.get(Calendar.YEAR);
}
return resultDateStr;
}
public static String convertMonth(int month) {
if (month == 0) return "January";
if (month == 1) return "February";
if (month == 2) return "March";
if (month == 3) return "April";
if (month == 4) return "May";
if (month == 5) return "June";
if (month == 6) return "July";
if (month == 7) return "August";
if (month == 8) return "September";
if (month == 9) return "October";
if (month == 10) return "November";
if (month == 11) return "December";
return null;
}
}

sell-- Calendar 和 Date- 01,月份不变年份+3或直接到2017的更多相关文章

  1. Java Date实现加一天,年月日类推往后+1,日期+1,月份+1,年份+1

    System.out.println("String类型 "+endDate); //页面传递到后台的时间 为String类型 SimpleDateFormat sdf = new ...

  2. Java 时间类-Calendar、Date、LocalDate/LocalTime

    1.Date 类 java.util.Date是一个"万能接口",它包含日期.时间,还有毫秒数,如果你只想用java.util.Date存储日期,或者只存储时间,那么,只有你知道哪 ...

  3. Java 中Calendar、Date、SimpleDateFormat学习总结

    在之前的项目中,经常会遇到Calendar,Date的一些操作时间的类,并且总会遇到时间日期之间的格式转化问题,虽然做完了但是总是忘记,记不清楚,每次还都要查找资料.今天总结一下,加深印象. Cale ...

  4. java中的日期操作Calendar和Date

    1. Calendar转Date Calendar calendar = Calendar.getInstance(); Date date = calendar.getTime(); 2. Date ...

  5. Time.MONTH及Calendar.MONTH 默认的月份为 0-11

    Time.MONTH及Calendar.MONTH 默认的月份为  0-11 所以使用的时候要自己加1.

  6. Calendar /String /Date 转换

    Calendar 转化 String Calendar calendat = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDate ...

  7. Calendar代替Date常用方法小记

    业务逻辑中遇到日期的相关操作,整理一下小做总结 日期操作离不开 java.util.Calendar 和 java.util.Date ,实体类中日期字段设计也可能用到java.sql.Date.但目 ...

  8. java输入月份,年份,显示对应月份的天数,

    总结:1,输入月份,年份,这需要用Scanner   2.我们已知道12个月份的天数,有30天,31天   3.判断闰年 用switch -case-break语句  4.注意不要忘了写break;判 ...

  9. calendar merge date

    calendar merge date componentDidMount () { const { monthDays, // monthDates, } = this.props; const d ...

随机推荐

  1. centos 下如何加入sudo 用户

    当在终端执行sudo命令时,系统提示“ jackluo is not in the sudoers file”: $ sudo ls Password:jackluo is not in the su ...

  2. asp.net 微信企业号办公系统-表单及流程设计配置实例

    在环境搭建好之后,我们就来学习一下怎样快速创建一个流程,并执行和流转该流程(我们这里讲的只是入门,不涉及到具体流程参数设置). 创建一个流程步骤为:在数据库在创建表-->设计表单-->设置 ...

  3. PCL 1.4.0 VS 2010 Configuration

    Open VS2010, create a new project, then open Property Manager, double-click Microsoft.Cpp.win32.user ...

  4. [转] - linux下使用write\send发送数据报 EAGAIN : Resource temporarily unavailable 错

    linux下使用write\send发送数据报 EAGAIN : Resource temporarily unavailable 错 首先是我把套接字设置为异步的了,然后在使用write发送数据时采 ...

  5. Excel 中单元格和范围的引用(即访问的表示方法)

    计算机中,无非是数据和数据的处理这两件事.Excel的工作表能存储大量数据,除了这些原始数据,我们还要用函数来处理这些数据,比如求和求积,求平均值,排序等等,并把处理结果也存在单元格里.在Excel中 ...

  6. github上有android开源项目

    下面是一些比较好的开源项目,总共分为5大类,也许对某一些人有用,有些项目也许将来某一天对自己也有用,所以整理到此,希望对大家有帮助.首先声明非原创,这篇blog的目的是分享给那些可能需要的人. htt ...

  7. jQuery Ajax 确定 form 表单 submit 提交成功

    使用 jQuery 提交表单,可以使用 同步方式(async: false). a.html 是 html 文件,a.php 是服务端文件,把 a.html 中表单的数据提交到 a.php 中,在提交 ...

  8. Ubuntu 14.04 LTS 安装 VNC Viewer

    1.修改镜像源: /etc/apt/sources.list将"http://archive.ubuntu.com/ubuntu/"替换为: http://cn.archive.u ...

  9. ucos

    优先级反转:有信号量的时候,不同任务共用一个信号量,如果信号量没释放就可能出现优先级反转. μC/OS-Ⅱ支持的处理器的堆栈既可以从上(高地址)往下(低地址)递减也可以从下往上递增.用户在调用OSTa ...

  10. shell常用代码

    grep -lr 'hello' /usr/share/* #在/usr/share目录下查找包含hello的字符串 NOW_DATE=`date "+%Y%m%d%H%M%S"` ...