代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
作者:
/ 发布于
2021/4/25
/
968
ublic static final String DATEFORMAT_PATTERN_THREE = "yyyy-MM-dd"; /** * 根据时间返回对应的周 传入时间格式 yyyy-MM-dd * * @param day 2019-07-01 2019-07-31 * @return 2019-07-w1 2019-07-w5 */ public static String transDay(String day){ String num = day.substring(8,10); String flag = "w1"; switch (num){ case "01": case "02": case "03": case "04": case "05": case "06": case "07": flag = "w1"; break; case "08": case "09": case "10": case "11": case "12": case "13": case "14": flag = "w2"; break; case "15": case "16": case "17": case "18": case "19": case "20": case "21": flag = "w3"; break; case "22": case "23": case "24": case "25": case "26": case "27": case "28": flag = "w4"; break; case "29": case "30": case "31": flag = "w5"; break; } return day.substring(0,8)+flag; } public static String getLastWeekStart(Date now) { String startYear = ""; String startMonth = ""; String startDay = ""; SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT_PATTERN_THREE); String date = sdf.format(now); Calendar cl = Calendar.getInstance(); cl.setTime(now); String week = transDay(date).substring(8,10); switch (week){ case "w1" : cl.add(Calendar.MONTH,-1); if((cl.get(Calendar.MONTH)+1)==2) { if(isLeapYear(cl.get(Calendar.YEAR))){ startDay = "29"; }else{ startDay = "22"; } }else { startDay = "29"; } break; case "w2" : startDay = "01"; break; case "w3" : startDay = "08"; break; case "w4" : startDay = "15"; break; case "w5" : startDay = "22"; break; } startYear = cl.get(Calendar.YEAR)+""; //获取年 if((cl.get(Calendar.MONTH) + 1)<10){ startMonth = "0"+(cl.get(Calendar.MONTH) + 1); //获取月份,0表示1月份 }else{ startMonth = ""+(cl.get(Calendar.MONTH) + 1); } return startYear +"-" +startMonth + "-" + startDay + " 00:00:000" ; } public static String getLastWeekEnd(Date now) { String endYear = ""; String endMonth = ""; String endDay = ""; SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT_PATTERN_THREE); String date = sdf.format(now); Calendar cl = Calendar.getInstance(); cl.setTime(now); String week = transDay(date).substring(8,10); switch (week){ case "w1" : cl.add(Calendar.MONTH,-1); endDay = cl.getActualMaximum(Calendar.DAY_OF_MONTH)+""; break; case "w2" : endDay = "07"; break; case "w3" : endDay = "14"; break; case "w4" : endDay = "21"; break; case "w5" : endDay = "28"; break; } endYear = cl.get(Calendar.YEAR)+""; //获取年 if((cl.get(Calendar.MONTH) + 1)<10){ endMonth = "0"+(cl.get(Calendar.MONTH) + 1); //获取月份,0表示1月份 }else{ endMonth = ""+(cl.get(Calendar.MONTH) + 1); } return endYear +"-" +endMonth + "-" + endDay + " 23:59:999" ; } public static boolean isLeapYear(int year ){ if(year % 4 != 0 || year % 100 == 0 && year % 400 != 0) { return false; }else { return true; } } /** * 根据开始日期 结束日期 获取相关周 * @param startTime * @param endTime * @return */ public static List<String> getListTransDay(String startTime,String endTime){ SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT_PATTERN_THREE); List<String> result = new ArrayList<>(); try { Date sDate = sdf.parse(startTime); Date eDate = sdf.parse(endTime); Calendar cls = Calendar.getInstance(); cls.setTime(sDate); Calendar cle = Calendar.getInstance(); cle.setTime(eDate); String tempTime = null; String trans = null; while(!(cls.get(Calendar.YEAR)+ ""+cls.get(Calendar.MONTH) +""+ cls.get(Calendar.DATE)+"").equals (cle.get(Calendar.YEAR) + ""+cle.get(Calendar.MONTH) +""+(cle.get(Calendar.DATE)+1)+"") ) { tempTime = sdf.format(cls.getTime()); trans = transDay(tempTime); result.add(trans); cls.add(Calendar.DATE,1); } } catch (ParseException e) { e.printStackTrace(); } result = result.stream().distinct().collect(Collectors.toList()); return result; }
试试其它关键字
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
贡献的其它代码
Label
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3