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
    *
    */

     

  • 相关阅读:
    G
    ZOJ 3782
    23.内存池
    22.boost图模板
    21.boost Ford最短路径算法(效率低)
    20.boost dijkstra最短路径算法
    19.boost A*算法
    18.boost 图的拓扑排序
    17.广度优先遍历bfs
    16.boost图深度优先遍历DFS
  • 原文地址:https://www.cnblogs.com/xiaobuild/p/2177072.html
Copyright © 2011-2022 走看看