Android获取时间
java代码:
SimpleDateFormat formatter = new SimpleDateFormat ('yyyy年MM月dd日 HH:mm:ss ');
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);
复制代码
以上可以获取当前的年月时分,也可以分开写(如下):
java代码:
SimpleDateFormat sDateFormat = new SimpleDateFormat('yyyy-MM-dd hh:mm:ss');
String date = sDateFormat.format(new java.util.Date());
如果想获取当前的年月,则可以这样写(只获取时间或秒种一样):
java代码:
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()));
如何获取Android系统时间是24小时制还是12小时制:
java代码:
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');
}
取得系统日期:
java代码:
Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR)
month = c.grt(Calendar.MONTH)
day = c.get(Calendar.DAY_OF_MONTH)
取得系统时间:
java代码:
Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE)
利用Time获取:
java代码:
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;
Android获取时间的更多相关文章
- android 获取时间
首先,先说下java下可以正常使用的方法: import java.text.DateFormat; import java.text.SimpleDateFormat; import java.ut ...
- Android获取时间2
Android开发之获取系统12/24小时制的时间 时间 2014-08-19 08:13:22 CSDN博客 原文 http://blog.csdn.net/fengyuzhengfan/art ...
- Android获取系统时间方法的总结
Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...
- android中获取时间
android中获取时间 1)通过calendar类获取 Calendar calendar = Calendar.getInstance();int moth = calendar.get(Cale ...
- Android 获取系统时间和网络时间
有些时候我们的应用中只能使用网络时间,而不能使用系统的时间,这是为了避免用户关闭了使用网络时间的功能后所产生的误差. 直接上代码. 1.清单文件中网络添加权限. <!-- 访问Internet资 ...
- Android获取系统时间的多种方法
Android中获取系统时间有多种方法,可分为Java中Calendar类获取,java.util.date类实现,还有android中Time实现. 现总结如下: 方法一: ? 1 2 3 4 5 ...
- Android获取网络时间的方法
一.通过免费或者收费的API接口获取 1.免费 QQ:http://cgi.im.qq.com/cgi-bin/cgi_svrtime 淘宝:http://api.m.taobao.com/rest/ ...
- android 获取Datepicker日期
1.使用的Android5.0系统,实现上面效果使用了alertdialog 2.布局文件: layout_dataselect <?xml version="1.0" en ...
- android开发时间和日期的代码实现工具类(一)
android开发时间和日期工具类的代码实现: package com.gzcivil.utils; import android.annotation.SuppressLint; import an ...
随机推荐
- MAGIC XPA最新版本Magic xpa 2.4c Release Notes
New Features, Feature Enhancements and Behavior ChangesSubforms – Behavior Change for Unsupported Ta ...
- vtk保存图像
vtkWindowToImageFilter * wif = vtkWindowToImageFilter::New(); vtkBMPWriter *bmpw = vtkBMPWriter::New ...
- 2.2 ARM处理器工作模式
ARM Architecture Reference Manual Arm 指令框架手册 种工作模式 Processor mode Mode number Description User usr 0 ...
- Java基础(二) ---- 继承(Inheritance)
- APNS 服务推送通知
1. 将app注册notification里面, 并从APNS上获取测试机的deviceToken. - (BOOL)application:(UIApplication *)application ...
- 数据库的NULL值讨论
有许多关于数据库设计中NULL的讨论,我个人的设计习惯是,不使用NULL值. 我所设计所有表都是Not Null的字段的,尤其是我主要做数据仓库的表设计.刚开始使用数据库时,就栽了一次.一个Group ...
- ORCLE基本语句(二)
select语句的基本语法: [ORDER BY < COLUMN1, COLUMN2, COLUMN3...> [ASC 或 DESC]]
- 3、C#面向对象:封装、继承、多态、String、集合、文件(下)
面向对象多态 一.装箱和拆箱 装箱:将值类型转换为引用类型.object o = 1:值类型给引用类型赋值 拆箱:将引用类型转换为值类型.int n = (int)o; 强制转换为值类型 满足条件:两 ...
- 深入理解JS异步编程五(脚本异步加载)
异步脚本加载 阻塞性脚本 JavaScript在浏览器中被解析和执行时具有阻塞的特性,也就是说,当JavaScript代码执行时,页面的解析.渲染以及其他资源的下载都要停下来等待脚本执行完毕 浏览器是 ...
- Build OpenCV text(OCR) module on windows
Background. AOI software needs to use the OCR feature to recognize the texts on the chips. Because o ...