java p如何配置日期格式,JAVA 日期格式转换设置

/*** 获取当前日期年月日时分秒yyyy-MM-dd HH:mm:ss

*

*@return

*/

public staticString getDateTime() {

SimpleDateFormat simpleFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date now= newDate();returnsimpleFormat.format(now);

}/*** 获取当前日期年月日时分秒yyyy-MM-dd*/

public staticString getDateYMD() {

SimpleDateFormat simpleFormat= new SimpleDateFormat("yyyy-MM-dd");

Date now= newDate();returnsimpleFormat.format(now);

}/*** 将string日期 转为 date*/

public staticDate StrToDate(String str) {

SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date date= null;try{

date=format.parse(str);

}catch(ParseException e) {

e.printStackTrace();

}returndate;

}/*** @Title: getTimeByMOnthAfterDay 参数时间date 转为对应格式

*@param:@paramdate 要转换的时间

*@param:@paramformatstring 格式"yyyy-MM-dd HH:mm:ss", "yyyy-M-d H:m:s", "yyyy-MM-dd H:m:s", "yyyy-M-d HH:mm:ss"

*@param:@return*@return: String*/

public staticString getTimeByTransformation(Date date, String formatstring) {

Calendar cal=Calendar.getInstance();

cal.setTime(date);

SimpleDateFormat simpleFormat= newSimpleDateFormat(formatstring);returnsimpleFormat.format(cal.getTime());

}/*** 参数时间当月最后一天

*@param:@paramdate 要转换的时间

*@param:@paramformatstring 格式"yyyy-MM-dd HH:mm:ss", "yyyy-M-d H:m:s", "yyyy-MM-dd H:m:s", "yyyy-M-d HH:mm:ss"*/

public staticString getTimeByMOnthAfterDay(Date date, String formatstring) {

Calendar cal=Calendar.getInstance();

cal.setTime(date);

cal.set(Calendar.DAY_OF_MONTH,cal.getActualMaximum(Calendar.DAY_OF_MONTH));

SimpleDateFormat simpleFormat= newSimpleDateFormat(formatstring);returnsimpleFormat.format(cal.getTime());

}/*** 参数时间当月第一天

**@param:@paramdate 要转换的时间

*@param:@paramformatstring 格式"yyyy-MM-dd HH:mm:ss", "yyyy-M-d H:m:s", "yyyy-MM-dd H:m:s", "yyyy-M-d HH:mm:ss"*/

public staticString getTimeByMOnthFirstDay(Date date, String formatstring) {

Calendar cal=Calendar.getInstance();

cal.setTime(date);

cal.set(Calendar.DAY_OF_MONTH,1);

SimpleDateFormat simpleFormat= newSimpleDateFormat(formatstring);returnsimpleFormat.format(cal.getTime());

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值