日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

在Android中獲取當(dāng)前日期的4種方法

 hncdman 2022-04-27

In this tutorial I will show you 4 different ways to get current date in android.

在本教程中,我將向您展示4種不同的方法來(lái)獲取android中的當(dāng)前日期。

For doing this we will use Calendar, Date, SimpleDateFormate and System class.

為此,我們將使用Calendar,Date,SimpleDateFormate和System類(lèi)。

如何在Android中獲取當(dāng)前日期? (How to Get Current Date in Android?)

Method 1:

方法1:

In this method we will use Calendar and SimpleDateFormate class.

在此方法中,我們將使用Calendar和SimpleDateFormate類(lèi)。

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");Calendar c = Calendar.getInstance();String date = sdf.format(c.getTime());

Method 2:

方法2:

We can use Calendar class to get current date in another way.

我們可以使用Calendar類(lèi)以另一種方式獲取當(dāng)前日期。

Calendar c = Calendar.getInstance();int day = c.get(Calendar.DAY_OF_MONTH);int month = c.get(Calendar.MONTH);int year = c.get(Calendar.YEAR);String date = day + "/" + (month+1) + "/" + year;

Method 3:

方法3:

In this method we will use Date and SimpleDateFormate class.

在此方法中,我們將使用Date和SimpleDateFormate類(lèi)。

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");String date = sdf.format(new Date());

Method 4:

方法4:

Another method in which we will use System and SimpleDateFormate class to get current date

我們將使用System和SimpleDateFormate類(lèi)獲取當(dāng)前日期的另一種方法

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");String date = sdf.format(System.currentTimeMillis());

Comment below if you know any other way to get current date in android.

如果您知道在Android中獲取當(dāng)前日期的任何其他方法,請(qǐng)?jiān)谙旅嬖u(píng)論。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類(lèi)似文章 更多