zoukankan      html  css  js  c++  java
  • java 时间转换

        public static int timestrtosec(String time) {
            if (Strings.isNullOrEmpty(time)) {
                return 0;
            }
            
            System.setProperty("user.timezone","GMT +08");
            String format = "yyyyMMddHHmmss";
            DateFormat dateFormat1 = new SimpleDateFormat(format, Locale.US);
            try {
                return (int) (dateFormat1.parse(time).getTime() / 1000);
            } catch (ParseException e) {
                e.printStackTrace();
            }

            return 0;
        }
         // timeZoneOffset 为时区
        public static String timeStamp2Date(String seconds, String format, int timeZoneOffset) {
            if (Strings.isNullOrEmpty(seconds) || seconds.equals("null")) {
                return "";
            }
            if (format == null || format.isEmpty())
                format = "yyyyMMddHH";
            
            if (timeZoneOffset > 13 || timeZoneOffset < -12) {
                timeZoneOffset = 0;
            }
            TimeZone timeZone;
            String[] ids = TimeZone.getAvailableIDs(timeZoneOffset * 60 * 60 * 1000);
            if (ids.length == 0) {
                timeZone = TimeZone.getDefault();
            } else {
                timeZone = new SimpleTimeZone(timeZoneOffset * 60 * 60 * 1000, ids[0]);
            }
        
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            sdf.setTimeZone(timeZone);
            
            return sdf.format(new Date(Long.valueOf(seconds + "000")));
        }

  • 相关阅读:
    【CSS】CSS 页面布局:盒子模型(内容区、边框、内边距、外边距)
    压缩/解压文件
    WebApiClient.JIT
    并行+异步执行操作
    JSON输出时不输出某些属性值
    ASP.NET MVC中Filter过滤器的使用
    使用git克隆github上的项目失败,报错error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054
    C# 实现WebSocket通信
    写日志
    list随机生成数值
  • 原文地址:https://www.cnblogs.com/chengxin1982/p/5802162.html
Copyright © 2011-2022 走看看