日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

java获取月末日期_Java用于取得当前日期相对应的月初,月末,季初,季末,年初,年末时间详解...

發(fā)布時(shí)間:2025/4/17 java 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java获取月末日期_Java用于取得当前日期相对应的月初,月末,季初,季末,年初,年末时间详解... 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

package com.zrar.date;

import java.util.Calendar;

/**

*

* 描述:此類(lèi)用于取得當(dāng)前日期相對(duì)應(yīng)的月初,月末,季初,季末,年初,年末,返回值均為String字符串

* 1、得到當(dāng)前日期 today()

* 2、得到當(dāng)前月份月初 thisMonth()

* 3、得到當(dāng)前月份月底 thisMonthEnd()

* 4、得到當(dāng)前季度季初 thisSeason()

* 5、得到當(dāng)前季度季末 thisSeasonEnd()

* 6、得到當(dāng)前年份年初 thisYear()

* 7、得到當(dāng)前年份年底 thisYearEnd()

* 8、判斷輸入年份是否為閏年 leapYear

*

* 注意事項(xiàng): 日期格式為:xxxx-yy-zz (eg: 2007-12-05)

*

* 實(shí)例:

*

* @author pure

*/

public class DateThis {

private int x; // 日期屬性:年

private int y; // 日期屬性:月

private int z; // 日期屬性:日

private Calendar localTime; // 當(dāng)前日期

public DateThis() {

localTime = Calendar.getInstance();

}

/**

* 功能:得到當(dāng)前日期 格式為:xxxx-yy-zz (eg: 2007-12-05)

* @return String

* @author pure

*/

public String today() {

String strY = null;

String strZ = null;

x = localTime.get(Calendar.YEAR);

y = localTime.get(Calendar.MONTH) + 1;

z = localTime.get(Calendar.DATE);

strY = y >= 10 ? String.valueOf(y) : ("0" + y);

strZ = z >= 10 ? String.valueOf(z) : ("0" + z);

return x + "-" + strY + "-" + strZ;

}

/**

* 功能:得到當(dāng)前月份月初 格式為:xxxx-yy-zz (eg: 2007-12-01)

* @return String

* @author pure

*/

public String thisMonth() {

String strY = null;

x = localTime.get(Calendar.YEAR);

y = localTime.get(Calendar.MONTH) + 1;

strY = y >= 10 ? String.valueOf(y) : ("0" + y);

return x + "-" + strY + "-01";

}

/**

* 功能:得到當(dāng)前月份月底 格式為:xxxx-yy-zz (eg: 2007-12-31)

* @return String

* @author pure

*/

public String thisMonthEnd() {

String strY = null;

String strZ = null;

boolean leap = false;

x = localTime.get(Calendar.YEAR);

y = localTime.get(Calendar.MONTH) + 1;

if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) {

strZ = "31";

}

if (y == 4 || y == 6 || y == 9 || y == 11) {

strZ = "30";

}

if (y == 2) {

leap = leapYear(x);

if (leap) {

strZ = "29";

}

else {

strZ = "28";

}

}

strY = y >= 10 ? String.valueOf(y) : ("0" + y);

return x + "-" + strY + "-" + strZ;

}

/**

* 功能:得到當(dāng)前季度季初 格式為:xxxx-yy-zz (eg: 2007-10-01)

* @return String

* @author pure

*/

public String thisSeason() {

String dateString = "";

x = localTime.get(Calendar.YEAR);

y = localTime.get(Calendar.MONTH) + 1;

if (y >= 1 && y <= 3) {

dateString = x + "-" + "01" + "-" + "01";

}

if (y >= 4 && y <= 6) {

dateString = x + "-" + "04" + "-" + "01";

}

if (y >= 7 && y <= 9) {

dateString = x + "-" + "07" + "-" + "01";

}

if (y >= 10 && y <= 12) {

dateString = x + "-" + "10" + "-" + "01";

}

return dateString;

}

/**

* 功能:得到當(dāng)前季度季末 格式為:xxxx-yy-zz (eg: 2007-12-31)

* @return String

* @author pure

*/

public String thisSeasonEnd() {

String dateString = "";

x = localTime.get(Calendar.YEAR);

y = localTime.get(Calendar.MONTH) + 1;

if (y >= 1 && y <= 3) {

dateString = x + "-" + "03" + "-" + "31";

}

if (y >= 4 && y <= 6) {

dateString = x + "-" + "06" + "-" + "30";

}

if (y >= 7 && y <= 9) {

dateString = x + "-" + "09" + "-" + "30";

}

if (y >= 10 && y <= 12) {

dateString = x + "-" + "12" + "-" + "31";

}

return dateString;

}

/**

* 功能:得到當(dāng)前年份年初 格式為:xxxx-yy-zz (eg: 2007-01-01)

* @return String

* @author pure

*/

public String thisYear() {

x = localTime.get(Calendar.YEAR);

return x + "-01" + "-01";

}

/**

* 功能:得到當(dāng)前年份年底 格式為:xxxx-yy-zz (eg: 2007-12-31)

* @return String

* @author pure

*/

public String thisYearEnd() {

x = localTime.get(Calendar.YEAR);

return x + "-12" + "-31";

}

/**

* 功能:判斷輸入年份是否為閏年

*

* @param year

* @return 是:true 否:false

* @author pure

*/

public boolean leapYear(int year) {

boolean leap;

if (year % 4 == 0) {

if (year % 100 == 0) {

if (year % 400 == 0) leap = true;

else leap = false;

}

else leap = true;

}

else leap = false;

return leap;

}

}

總結(jié)

以上是生活随笔為你收集整理的java获取月末日期_Java用于取得当前日期相对应的月初,月末,季初,季末,年初,年末时间详解...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。