博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在Android中获取当前日期的4种方法
阅读量:2513 次
发布时间:2019-05-11

本文共 1435 字,大约阅读时间需要 4 分钟。

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

在本教程中,我将向您展示4种不同的方法来获取android中的当前日期。

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

为此,我们将使用Calendar,Date,SimpleDateFormate和System类。

如何在Android中获取当前日期? (How to Get Current Date in Android?)

Method 1:

方法1:

In this method we will use Calendar and SimpleDateFormate class.

在此方法中,我们将使用Calendar和SimpleDateFormate类。

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类以另一种方式获取当前日期。

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类。

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类获取当前日期的另一种方法

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中获取当前日期的任何其他方法,请在下面评论。

翻译自:

转载地址:http://xrggb.baihongyu.com/

你可能感兴趣的文章
storm0.9.5集群安装
查看>>
国际银行业务种类
查看>>
Python selenium chrome打包exe后禁用控制台输出滚动日志
查看>>
求子数组的最大和
查看>>
ssm实现支付宝支付功能(图文详解)
查看>>
OpenJudge NOI题库 6266:取石子游戏
查看>>
CQOI2016 Number - 数位dp
查看>>
致以后可能会用到的angular(虽然没什么机会)
查看>>
JQuery --- 第六期 (Ajax)
查看>>
Python和Java编程题(六)
查看>>
8.2.1.15 ORDER BY Optimization ORDER BY 优化
查看>>
sort_buffer_size:
查看>>
mojo 关闭utf8
查看>>
数据库外连接简介
查看>>
Django搭建网站笔记
查看>>
设计模式的总结
查看>>
eclipse里面配置热部署
查看>>
Linq 根据list属性去重复
查看>>
201521123045 《JAVA程序设计》第1周学习总结 1
查看>>
PW试验-----verilog
查看>>