import javatextSimpleDateFormat;
import javautilDate;
public class Test {
/
@param args
/
public static void main(String[] args) {
// String str="<font face='Arial,Serif',size='+2' color='red'";
Date date=new Date();
SimpleDateFormat df=new SimpleDateFormat("yyyyMMdd");
String str=dfformat(date);
String str1=strsubstring(4, 6);
Systemoutprintln(str1);
}
}
//CalendarTestjava
//Calendar对象能很好解决你的问题
import javautilCalendar;
public class CalendarTest {
public static void main(String[] args) {
Calendar c = CalendargetInstance();
int y=cget(CalendarYEAR);//年
int M = cget(CalendarMONTH)+1;//月,注意这里要加1,计算机第一个月从0开始
int d = cget(CalendarDATE);//日
Systemoutprintln("年:"+y);
Systemoutprintln("月:"+M);
Systemoutprintln("日:"+d);
String dateStr = "";
dateStr+=y+"-"+(M<10"0":"")+M+"-"+(d<10"0":"")+d;
Systemoutprintln(dateStr);
}
}
/
获取指定月份的日历信息
@param year
年
@param month
月
@return
/
public static int[] getMonthCalendar(int year, int month) {
Calendar cl = CalendargetInstance();
clset(year, month, 1);
int firstDay = clgetMinimum(CalendarDAY_OF_MONTH);
int lastDay = clgetMaximum(CalendarDAY_OF_MONTH);
int[] day = new int[lastDay];
for (int i = 0; i < lastDay; i++) {
day[i] = i + firstDay;
}
return day;
}
Date date=new Date();
//获取月份
Systemoutprintln(dategetMonth()+1);
//获取日
Systemoutprintln(dategetDate());
//将yyyyMMdd转为date
public static Date getCoreToEmsDateStr(String dateStr){
DateFormat format = new SimpleDateFormat("yyyyMMdd");
Date d = null;
try{
d = formatparse(dateStr);
}catch(ParseException e){
eprintStackTrace();
}
return d;
}
public static String getDateAfterDays(Timestamp s,int days){
Timestamp currTimestamp = s;
for (int i=0;i<days;i++){
currTimestamp = getNextDate(currTimestamp);
}
return getDateTimeStr(currTimestamp,"3");
}
public static Timestamp getNextDate(javasqlTimestamp tsDate){
if(tsDate==null)
return null;
javautilCalendar calendar = CalendargetInstance();
calendarsetTime(tsDate);
return getDateTime(calendarget(CalendarYEAR),calendarget(CalendarMONTH)+1,calendarget(CalendarDATE)+1,
calendarget(CalendarHOUR_OF_DAY),calendarget(CalendarMINUTE),calendarget(CalendarSECOND));
}
public static javasqlTimestamp getDateTime(int year,int month,int day,int hour,int minute,int second){
javasqlTimestamp ts = null;
javautilDate dt = null;
javautilCalendar calendar = CalendargetInstance();
calendarclear();
calendarset(year,month-1,day,hour,minute,second);
dt = calendargetTime();
ts = new javasqlTimestamp(dtgetTime());
return ts;
}
/
比较两个时间是否相同
@param tsBeginDate
@param tsEndDate
@param bool
@return
/
public static long getDateInterval(Timestamp tsBeginDate,Timestamp tsEndDate,boolean bool){
long lDays = 0;
if(bool){
tsBeginDate = CommongetDateTime(CommongetDateString(tsBeginDate),bool);
}
if(tsBeginDate!=null&&tsEndDate!=null){
Log4jinfo("tsEndDategetTime ()===="+tsEndDate);
Log4jinfo("tsBeginDategetTime ()===="+tsBeginDate);
lDays = (tsEndDategetTime()-tsBeginDategetTime())/86400000+1;
Log4jinfo("lDays===="+lDays);
}
return lDays;
}
/
格式化成Timestamp类型
@param sDt
@param bool
@return
/
public static javasqlTimestamp getDateTime(String sDt,boolean bool){
try{
return javasqlTimestampvalueOf(sDt); //sDt format:yyyy-mm-dd hh:mm:ssfffffffff
}catch(IllegalArgumentException iae){
if(bool)
sDt = sDt+" 23:59:590";
else
sDt = sDt+" 00:00:000";
return javasqlTimestampvalueOf(sDt);
}
}
/
根据时间获取日期字符串
@param ts
@return
/
public static String getDateString(Timestamp ts){
if(ts==null)
return "";
Calendar calendar = CalendargetInstance();
calendarsetTime(ts);
String strMonth = StringvalueOf(calendarget(CalendarMONTH)+1);
if(strMonthlength()==1){
strMonth = "0"+strMonth;
}
String strDay = StringvalueOf(calendarget(CalendarDATE));
if(strDaylength()==1){
strDay = "0"+strDay;
}
return calendarget(CalendarYEAR)+"-"+strMonth+"-"+strDay;
}
以上就是关于如何在java中获得当前系统时间的月份,并以“01”这样的格式输出全部的内容,包括:如何在java中获得当前系统时间的月份,并以“01”这样的格式输出、JAVA 如何单独取得"年","月","日"...、java 怎么获取一个月的日期等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)