android 中 系统日期时间的获取
- import java.text.SimpleDateFormat;
- SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss ");
- Date curDate = new Date(System.currentTimeMillis());//获取当前时间
- String str = formatter.format(curDate);
可以获取当前的年月时分,也可以分开写:
- SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
- String date = sDateFormat.format(new java.util.Date());
如果想获取当前的年月,则可以这样写(只获取时间或秒种一样):
- SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM");
- String date=sdf.format(new java.util.Date());
当然还有就是可以指定时区的时间(待):
- df=DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.CHINA);
- System.out.println(df.format(new Date()));
- ContentResolver cv = this.getContentResolver();
- String strTimeFormat = android.provider.Settings.System.getString(cv,
- android.provider.Settings.System.TIME_12_24);
- if(strTimeFormat.equals("24"))
- {
- Log.i("activity","24");
- }
- Calendar c = Calendar.getInstance();
- 取得系统日期:year = c.get(Calendar.YEAR)
- month = c.grt(Calendar.MONTH)
- day = c.get(Calendar.DAY_OF_MONTH)
- 取得系统时间:hour = c.get(Calendar.HOUR_OF_DAY);
- minute = c.get(Calendar.MINUTE)
利用Calendar获取
- Calendar c = Calendar.getInstance();
- 取得系统日期:year = c.get(Calendar.YEAR)
- month = c.grt(Calendar.MONTH)
- day = c.get(Calendar.DAY_OF_MONTH)
- 取得系统时间:hour = c.get(Calendar.HOUR_OF_DAY);
- minute = c.get(Calendar.MINUTE)
- Calendar c = Calendar.getInstance();
- 取得系统日期:year = c.get(Calendar.YEAR)
- month = c.grt(Calendar.MONTH)
- day = c.get(Calendar.DAY_OF_MONTH)
- 取得系统时间:hour = c.get(Calendar.HOUR_OF_DAY);
- minute = c.get(Calendar.MINUTE)
利用Time获取
- Time t=new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料。
- t.setToNow(); // 取得系统时间。
- int year = t.year;
- int month = t.month;
- int date = t.monthDay;
- int hour = t.hour; // 0-23
- int minute = t.minute;
- int second = t.second;
唯一不足是取出时间只有24小时模式.
android 中 系统日期时间的获取的更多相关文章
- Android中关于日期时间与时区的使用总结
在开发Android的过程中,出现过几次由于日期时间导致的问题,而且主要是由于时区的原因导致,所以一直想总结一下,形成一个良好的开发规范. 一.Unix时间戳 Unix时间戳(Unix tim ...
- Android 系统日期时间的获取
import java.text.SimpleDateFormat; SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月 ...
- Android中实现日期时间选择器(DatePicker和TimePicker)
利用Android应用框架提供的DatePicker(日期选择器)和TimePicker(时间选择器),实现日期时间选择器. Dialog的Content布局文件(date_time_dialog.x ...
- Android实践 -- 设置系统日期时间和时区
设置系统日期时间和时区 设置系统的日期时间和时区,需要 系统权限和系统签名,android:sharedUserId="android.uid.system" 需要在manifes ...
- 我使用过的Linux命令之date - 显示、修改系统日期时间
原文地址:http://www.cnblogs.com/diyunpeng/archive/2011/11/20/2256538.html 用途说明 ate命令可以用来显示和修改系统日期时间,注意不是 ...
- 在mysql数据库中关于日期时间字段的处理
在mysql数据库中关于日期时间字段的处理 在开发中,日期时间字段一般有如下几种设计 假设要获取2013-08-15日到2013-08-16日之间的记录 1. 直接使用日期时间类字段 相关sql语句如 ...
- 我使用过的Linux命令之date - 显示、修改系统日期时间(转)
用途说明 ate命令可以用来显示和修改系统日期时间,注意不是time命令. 常用参数 格式:date 显示当前日期时间. 格式:date mmddHHMM 格式:date mmddHHMMYYYY 格 ...
- JavaScript中的日期时间函数
1.Date对象具有多种构造函数,下面简单列举如下 new Date() new Date(milliseconds) new Date(datestring) new Date(year, mont ...
- 【Java8新特性】关于Java8中的日期时间API,你需要掌握这些!!
写在前面 Java8之前的日期和时间API,存在一些问题,比如:线程安全的问题,跨年的问题等等.这些问题都在Hava8中的日期和时间API中得到了解决,而且Java8中的日期和时间API更加强大.立志 ...
随机推荐
- How to Customize Server Header using NginX headers-more module
http://wiki.nginx.org/HttpHeadersMoreModule#Version headers_more When you are browsing a website, yo ...
- iOS开发 .framework的Optional(弱引用)和Required(强引用)区别, 有错误 Library not found………………
http://www.cnblogs.com/wanyakun/p/3494323.html 强引用(Required)的framework是一定会被加载到内存的,但是弱引用(Optional)的fr ...
- Add controls dynamically in flowlayoutpanel
For a FlowLayoutPanel, you don't need to specify a location since the controls are arranged for you. ...
- POJ 2502 Subway dij
这个题的输入输出注意一下就好 #include<cstdio> #include<cstring> #include<queue> #include<cstd ...
- [转]ASP.NET MVC 入门9、Action Filter 与 内置的Filter实现(介绍)
有时候你想在调用action方法之前或者action方法之后处理一些逻辑,为了支持这个,ASP.NET MVC允许你创建action过滤器.Action过滤器是自定义的Attributes,用来标记添 ...
- 曲面Shader
这是一个能让平面呈现出曲面效果的Shaer. 代码: Shader "Custom/CurvedWorld"{ Properties { // Diffuse texture _M ...
- Html笔记(二)字体
字体标签:<font> 例:<font size=5 color=red>字体标签示例</font> 注:简单颜色可以直接写对应的英文,复杂的颜色用16进制表示,表 ...
- tail -f logfile.log 一直监控某个文件,若该文件有改动,立即在屏幕上输出
tail -f logfile.log 可以一直监控某个文件,只要文件有改动,就立即在屏幕上输出
- sql中用逗号拼接字符串
MSSQL中可以用STUFF函数拼接成字符串. 如: SELECT FieldSomeElse, ( SELECT STUFF(( SELECT ',' + LinkField FROM Detail ...
- IntelliJ IDEA的下载、安装和WordCount的初步使用(本地模式和集群模式)
包括: IntelliJ IDEA的下载 IntelliJ IDEA的安装 IntelliJ IDEA中的scala插件安装 用SBT方式来创建工程 或 选择Scala方式来创建工程 本地模式或集群 ...