zoukankan      html  css  js  c++  java
  • 获取时间并替换到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
    *
    */

     

  • 相关阅读:
    集合容器
    洛谷P3953 逛公园
    洛谷P1967 货车运输
    洛谷P1073 最优贸易
    洛谷P4568 [JLOI2011]飞行路线
    洛谷P1265 公路修建
    洛谷P1503 鬼子进村
    洛谷P1613 跑路
    洛谷P4933 大师
    洛谷P4017 最大食物链计数
  • 原文地址:https://www.cnblogs.com/xiaobuild/p/2177072.html
Copyright © 2011-2022 走看看