Chinaunix
标题:
获取时间并替换到String.xml 中
[打印本页]
作者:
听老歌
时间:
2011-09-15 11:47
标题:
获取时间并替换到String.xml 中
获取时间并替换到String.xml 中
调用System.currentTimeMillis()获得当前时间
SimpleDateFormat format=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");Date date=new Date(System.currentTimeMillis());Log.i("myDebug", ""+date);Log.i("myDebug", ""+format.format(date));/*打印结果: * Thu Sep 15 10:22:27 GMT+08:00 2011* 2011年09月15日 10:22:27* */
调用new java.util.Date()获取当前时间
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date date2=new java.util.Date(); Log.i("myDebug", ""+date2);Log.i("myDebug", ""+format2.format(date2));/*打印结果 * Thu Sep 15 10:25:52 GMT+08:00 2011 * 2011-09-15 10:25:52 * */
复制代码
string.xml定义
<string name="time">现在北京时间%1$s</string>%后1表示中有一个值需要修改,s表示字符串;另外d表示是整型
java:
String text = String.format(getString(R.string.time), format.format(date));Log.i("myDebug", ""+text);/*打印结果:*现在北京时间2011年09月15日 10:40:40**/
复制代码
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2