zoukankan      html  css  js  c++  java
  • 时间戳和字符串转换

    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    public class test {
     public static void main(String[] args) {
      String time = "2010年12月08日11时17分00秒";
      System.out.println(time); // 字符串=======>时间戳
      String re_str =getTime(time);
      System.out.println(re_str);  //时间戳======>字符串
      String data =getStrTime(re_str);
      System.out.println(data);
     }
     // 将字符串转为时间戳
      public static String getTime(String user_time) {
       String re_time = null;
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
       Date d;
       try {
        d = sdf.parse(user_time);
        long l = d.getTime();
        String str = String.valueOf(l);
        re_time =str.substring(0, 10);
        } catch(ParseException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
        }
        return re_time;
       }
      
      // 将10位时间戳转为字符串
      public static String getStrTime(String cc_time) {
       String re_StrTime = null;
       SimpleDateFormat sdf =new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
       // 例如:cc_time=1291778220
       long lcc_time =Long.valueOf(cc_time);
       re_StrTime =sdf.format(new Date(lcc_time * 1000L));
       return re_StrTime;
     }
    }

    如果是13位呢?   lcc_time 不用 *1000L ?

  • 相关阅读:
    解读:MultipleOutputs类
    hadoop2对应的eclipse插件使用
    MR案例:外连接代码实现
    Navicat for MySQL下载、安装与破解
    MySQL数据库安装与配置详解
    堡垒机2
    堡垒机
    MySQL主键和外键使用及说明
    待续--mysql中key 、primary key 、unique key 与index区别
    ORM框架SQLAlchemy使用学习
  • 原文地址:https://www.cnblogs.com/myfrank/p/8651065.html
Copyright © 2011-2022 走看看