android中实现求昨天的日期的代码工具类
来源:互联网 发布:php数据库输出乱码 编辑:程序博客网 时间:2024/04/20 14:16
前段时间在做项目的时候,突然要用到昨天的日期进行查询数据.在网上也没有找到类似的东西,就自己写了一个
package com.yunduan.util;
public class Yesterday {
public String getYesterday(String date){
String[] strs=date.split("-");
String yesterday="";
int year=Integer.parseInt(strs[0]);
int mounth=Integer.parseInt(strs[1]);
int day=Integer.parseInt(strs[2]);
String newDay="";
if(day-1<10){
newDay="0"+(day-1);
}else{
newDay=day-1+"";
}
String newMounth="";
if(mounth-1<10){
newMounth="0"+(mounth-1);
}else{
newMounth=mounth-1+"";
}
String newYear=year-1+"";
if(Integer.parseInt(newDay)>=1){
if(mounth<10){
newMounth="0"+mounth;
yesterday=year+"-"+newMounth+"-"+newDay;
}else{
yesterday=year+"-"+mounth+"-"+newDay;
}
}else{
if(Integer.parseInt(newMounth)>=1){
if(newMounth.equals("2")){
if(year%400==0||(year%4==0&&year%100!=0)){
newDay=29+"";
}else{
newDay=28+"";
}
}else if(newMounth.equals("1")||newMounth.equals("3")||newMounth.equals("5")||newMounth.equals("7")||newMounth.equals("8")||newMounth.equals("10")||newMounth.equals("12")){
newDay=31+"";
}else{
newDay=30+"";
}
yesterday=year+"-"+newMounth+"-"+newDay;
}else{
yesterday=newYear+"-12-31";
}
}
return yesterday;
}
}
0 0
- android中实现求昨天的日期的代码工具类
- 昨天的日期
- 获取昨天的日期
- 获取昨天的日期
- 简单代码实现(补昨天的.....)
- 关于java代码中求两个日期差的方法
- Java中获取明天或者昨天的日期的方法
- 用Java实现今天、昨天、前天的日期小例子。
- 如何取得昨天的日期
- ios获取昨天的日期
- golang获取昨天的日期
- MATLAB计算昨天的日期
- js获取昨天的日期
- java 获取昨天的日期
- java获取昨天的日期
- 昨天写的代码
- 昨天的代码
- SQL求昨天的时间
- Merge into的注意点之ORA-30926
- clear:both 的妙用
- Linux 配置笔记
- 通州首家民营文化企业——点创世纪文化传播有限公司成功上市
- 自定义实现String类
- android中实现求昨天的日期的代码工具类
- NSNumber
- java内部类的基本理解
- android自定义view粒子效果之雨-续
- DFS Construct Binary Tree from Preorder and Inorder Traversal
- 单点登录(SSO)服务
- Spring MVC之@RequestParam @RequestBody @RequestHeader 等详解
- Spring MVC基础
- 《剑指Offer》学习笔记--面试题43:n个骰子的点数