/*
    * 将String转成Date类型
    * 将GMT时间转换成当前时区时间
    */
    public static String transform(String from){
        String to = "";


        SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //本地时区
        Calendar nowCal = Calendar.getInstance();
        TimeZone localZone = nowCal.getTimeZone();
        //设定SDF的时区为本地
        simple.setTimeZone(localZone);


        SimpleDateFormat simple1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //设置 DateFormat的时间区域为GMT
        simple1.setTimeZone(TimeZone.getTimeZone("GMT"));


        //把字符串转化为Date对象,然后格式化输出这个Date
        Date fromDate = new Date();
        try {
            //时间string解析成GMT时间
            fromDate = simple1.parse(from);
            //GMT时间转成当前时区的时间
            to = simple.format(fromDate);
        } catch (ParseException e1) {
            e1.printStackTrace();
        }
        return to;
    }

更多相关文章

  1. Android Studio如何轻松整理字符串到string.xml中
  2. android每隔5s显示时间
  3. Android实现DES对字符串加密
  4. Android中实现日期时间选择器(DatePicker和TimePicker)
  5. Android中修改系统时间的几种方式
  6. Android中判断字符串中必须包含字母或者数字_Android
  7. android9.0 系统默认时间修改
  8. android 日期时间选择器
  9. android 设置时区

随机推荐

  1. 通过android代码获取android系统的imei、
  2. 使用平台的风格和主题
  3. WebView的使用之Android与JS通过WebView
  4. 【Android(安卓)应用开发】Android资源文
  5. Android跨进程通信IPC
  6. android 中 多个Activity 的跳转 与传值
  7. Android的Camera架构介绍
  8. Android中的shape中的属性大全
  9. Android焦点分发基本流程
  10. Android如何监听开机广播和关机广播