• 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")));
        }

  • 相关阅读:
    设备arduino的编译目录
    c# await 关键字错误
    开篇 hello 内Cool超人
    在Windows Azure虚拟机上开发Windows 8 应用
    使用LVS实现负载平衡之Windows Server 2008配置
    IDC Digital Transition Annual Festival(2018.10.19)
    Dell Technology Summit(2018.10.17)
    Lean Data Innovation Sharing Salon(2018.09.15)
    Trusted Block Chain Summit(2018.10.09)
    Artificial Intelligence Computing Conference(2018.09.12)
  • 原文地址:https://www.cnblogs.com/chengxin1982/p/5802162.html
Copyright © 2020-2023  润新知