/*
* Copyright (c) 2018 ADTEC
* All rights reserved
*
* 本程序为自由软件;您可依据自由软件基金会所发表的GNU通用公共授权条款规定,就本程序再为发布与/或修改;无论您依据的是本授权的第二版或(您自行选择的)任一日后发行的版本。
* 本程序是基于使用目的而加以发布,然而不负任何担保责任;亦无对适售性或特定目的适用性所为的默示性担保。详情请参照GNU通用公共授权。
*/
package com.nxy.nfpp.nfpp_inside.busi.slim;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* 获取当前时间字符串(yyyy-MM-dd HH:mm:ss)
*
* @return
*/
public static String getNowTmStr() {
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return df.format(date);
}
/**
* 获取机器日期
*
* @return
*/
public static String getNowDate() {
Date date = new Date();// 创建一个时间对象,获取到当前的时间
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd
// HH:mm:ss");//设置时间显示格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String str = sdf.format(date);// 将当前时间格式化为需要的类型
// System.out.println(str);//输出结果
return str;
}
/**
* 获取机器日期
*
* @return
*/
public static String getNextDate() {
Date date = new Date();// 创建一个时间对象,获取到当前的时间
Calendar cal=Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, +1);
date=cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String str = sdf.format(date);// 将当前时间格式化为需要的类型
return str;
}
/**
* 获取机器月日
*
* @return
*/
public static String getDate() {
Date date = new Date();// 创建一个时间对象,获取到当前的时间
SimpleDateFormat sdf = new SimpleDateFormat("MMdd");
String str = sdf.format(date);// 将当前时间格式化为需要的类型
// System.out.println(str);//输出结果
return str;
}
/**
* 获取本周第一天日期
*
* @return
*/
public static String getWeekStartDate(){
Calendar cal = Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
Date date = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String str = sdf.format(date);
return str;
}
/**
* 获取本周最后一天日期
*
* @return
*/
public static String getWeekEndDate(){
Calendar cal = Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
Date date = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String str = sdf.format(date);
return str;
}
/**
* 获取月
*
* @return
*/
public String getMonthDate() {
Date date = new Date();// 创建一个时间对象,获取到当前的时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
String str = sdf.format(date);// 将当前时间格式化为需要的类型
return str;
}
/**
* 获取本月第一天日期
*
* @return
*/
public static String getLastDayOfMonth() {
Calendar cal = Calendar.getInstance();
//获取某月最大天数
int lastDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
//设置日历中月份的最大天数
cal.set(Calendar.DAY_OF_MONTH, lastDay);
//格式化日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String lastDayOfMonth = sdf.format(cal.getTime());
return lastDayOfMonth;
}
/**
* 获取本月最后一天日期
*
* @return
*/
public static String getEndDayOfMonth() {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
Calendar ca = Calendar.getInstance();
ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
String end = format.format(ca.getTime());
return end;
}
/**
* 获取年
*
* @return
*/
public static String getYearDate() {
Date date = new Date();// 创建一个时间对象,获取到当前的时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
String str = sdf.format(date);// 将当前时间格式化为需要的类型
return str;
}
/**
* 获取月日
*
* @return
*/
public static String getMoDyDate() {
Date date = new Date();// 创建一个时间对象,获取到当前的时间
SimpleDateFormat sdf = new SimpleDateFormat("MMdd");
String str = sdf.format(date);// 将当前时间格式化为需要的类型
return str;
}
}
公共日期类
猜你喜欢
转载自blog.csdn.net/A15712399740/article/details/86539421
今日推荐
周排行