JAVA中DATE如何光取日期时间,不取多余的

JAVA中DATE如何光取日期时间,不取多余的,第1张

用SimpleDateFormat这个类来获取当前系统时间 下面为例子程序

import javatextSimpleDateFormat;

import javautilDate;

public class Time {

public static void main(String[] args) {

SimpleDateFormat format = new SimpleDateFormat(

"yyyy年-M月-d日 kk时:m分:ss秒 E ");

String s = formatformat(new Date());

Systemoutprintln(s);

}

}

输出:2008年-7月-14日 21时:50分:02秒 星期一

Date date=new Date();

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

String time=formatformat(date);

不同的方法介绍如下:

1、通过Date类来获取当前时间。

Date day=new Date()

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

Systemoutprintln(dfformat(day))

2、通过System类中的currentTimeMillis方法来获取当前时间。

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   Systemoutprintln(dfformat(SystemcurrentTimeMillis()))

3、通过Calendar类来获取当前时间。

Calendar c = CalendargetInstance();//可以对每个时间域单独修改

int year = cget(CalendarYEAR)

int month = cget(CalendarMONTH)

int date = cget(CalendarDATE)

int hour = cget(CalendarHOUR_OF_DAY)

int minute = cget(CalendarMINUTE)

int second = cget(CalendarSECOND)

Systemoutprintln(year + "/" + month + "/" + date + " " +hour + ":" +minute + ":" + second)

4、通过Date类来获取当前时间。

Date date = new Date()

String year = Stringformat("%tY", date)

String month = Stringformat("%tB", date)

String day = Stringformat("%te", date)

Systemoutprintln("今天是:"+year+"-"+month+"-"+day)

以上就是关于JAVA中DATE如何光取日期时间,不取多余的全部的内容,包括:JAVA中DATE如何光取日期时间,不取多余的、java中怎么得到当前时间的小时、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9514086.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存