Calendar c=CalendargetInstance();
int y=cget(CalendarYEAR);
int m=cget(CalendarMONTH);
int d=cget(CalendarDATE);String date=y+"-"+m+"-"+d; Date d=javasqlDatevalueOf(time);
int date, month;
Date time = new Date(SystemcurrentTimeMillis());
date = timegetMonth()+1;
month = timegetDate()+1;
Systemoutprintln(month+"/"+date);
SimpleDateFormat fmt =new SimpleDateFormat("yyyy-MM-dd");
Date cDate = null;
// 与当前日期相差的天数,如果为+的话则当前日期往后+days天,否则往前-days天
int days = -7;
try {
String pattern = "yyyy-MM-dd";//获取的日期格式
SimpleDateFormat df = new SimpleDateFormat(pattern);
Date today = new Date();//获取当前日期
String currentDate = dfformat(today);//获取当前日期的字符串
Calendar cal=CalendargetInstance();
cDate = fmtparse(currentDate);
calsetTime(cDate);
caladd(CalendarDAY_OF_YEAR,days); //将日期+days获取你想要的日期
currentDate = fmtformat(calgetTime());
Systemoutprintln(currentDate);
} catch (ParseException e) {
eprintStackTrace();
}
now=new Date;
year=nowgetFullYear();
month=nowgetMonth()+1;
day=nowgetDate();
hour=nowgetHours();
minute=nowgetMinutes();
second=nowgetSeconds();
ms=nowgetMilliseconds();
public static void main(String[] s){
curDay(new Date(), "yyyy-MM-dd HH:mm:ss");
}
public static String curDay(Date date, String format) {
if (date != null) {
return new SimpleDateFormat(format)format(date);
}
return null;
}
参考一下:
import javatext;import javautilDate;
/
SimpleDateFormat函数语法:
G 年代标志符
y 年
M 月
d 日
h 时 在上午或下午 (1~12)
H 时 在一天中 (0~23)
m 分
s 秒
S 毫秒
E 星期
D 一年中的第几天
F 一月中第几个星期几
w 一年中第几个星期
W 一月中第几个星期
a 上午 / 下午 标记符
k 时 在一天中 (1~24)
K 时 在上午或下午 (0~11)
z 时区
/
public class FormatDateTime {
public static void main(String[] args) {
SimpleDateFormat myFmt=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
SimpleDateFormat myFmt1=new SimpleDateFormat("yy/MM/dd HH:mm");
SimpleDateFormat myFmt2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//等价于nowtoLocaleString()
SimpleDateFormat myFmt3=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒 E ");
SimpleDateFormat myFmt4=new SimpleDateFormat(
"一年中的第 D 天 一年中第w个星期 一月中第W个星期 在一天中k时 z时区");
Date now=new Date();
Systemoutprintln(myFmtformat(now));
Systemoutprintln(myFmt1format(now));
Systemoutprintln(myFmt2format(now));
Systemoutprintln(myFmt3format(now));
Systemoutprintln(myFmt4format(now));
Systemoutprintln(nowtoGMTString());
Systemoutprintln(nowtoLocaleString());
Systemoutprintln(nowtoString());
}
}
你想要哪个值,就传对应的字母进去就行了。
以上就是关于java如何获取当前系统时间需要用Date型的全部的内容,包括:java如何获取当前系统时间需要用Date型的、JAVA获取当前月和日(急!!!在线等)、java 获得当前日期,而不要当前时间的代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)