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更加强大.立志 ...
随机推荐
- BZOJ_1611_[Usaco2008_Feb]_Meteor_Shower流星雨_(bfs)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1611 网格图起始位置(0,0),不同时间会有流星落下,导致之后的时间里,该点以及周围四个点都不 ...
- Nagios ’status.cgi‘文件权限许可和访问控制漏洞
漏洞名称: Nagios ’status.cgi‘文件权限许可和访问控制漏洞 CNNVD编号: CNNVD-201307-013 发布时间: 2014-02-21 更新时间: 2014-02-21 危 ...
- apache开源项目--Cassandra
Apache Cassandra是一套开源分布式Key-Value存储系统.它最初由Facebook开发,用于储存特别大的数据.Facebook目前在使用此系统. 主要特性: 分布式 基于column ...
- Deep Learning Overview
[Ref: http://en.wikipedia.org/wiki/Deep_learning] Definition: a branch of machine learning based on ...
- 嵌入式 hi3518c裸板uboot烧写、kernel烧写、fs烧写小结
1.在uboot中我可以添加自己的命令,添加的方法是找到一个uboot的命令,然后模仿着去增加属于自己的命令代码以及实现函数就可以 2.记住在使用printf进行调试的时候,在遇到指针或者字符串的时候 ...
- 用Eclipse和GDB构建ARM交叉编译和在线调试环境
我们在 Linux 主机中搭建我们的开发环境,使用 Ubuntu 10.04 LTS 为例. 搭建应用开发环境 安装 JRE Eclipse 依赖于Java 环境,所以必须先安装 JRE 或 JD ...
- LightOJ 1245 Harmonic Number (II) 水题
分析:一段区间的整数除法得到的结果肯定是相等的,然后找就行了,每次是循环一段区间,暴力 #include <cstdio> #include <iostream> #inclu ...
- 树莓PI安装web服务器
参考:http://www.eeboard.com/bbs/forum.php?mod=viewthread&tid=27383 http://www.eeboard.com/bbs/thre ...
- 【HTML】Beginner7:Image
1.Image The web is not just about text,it is a multi-media extravaganza and the most common form ...
- Java笔记(十一)……单例设计模式
设计模式 解决某一类问题最行之有效的方法 Java中有23中设计模式 单例设计模式 解决一个类在内存中只存在一个对象 思路 将构造函数私有化 在类中创建一个本类对象 提供一个方法可以获取到对象 两种方 ...