/*
    * 将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 设置系统屏幕亮度
  2. android 查看 当前activity
  3. android:exported 属性详解
  4. Android(安卓)定时任务的多种实现方式
  5. Android——获取手机当前信号强度(dbm/asu值)
  6. Android(安卓)ApiDemos示例解析(15):App->Activity->SetWallpaper
  7. Android(安卓)设备+APP+号码信息
  8. Android(安卓)中文API (32) ―― TimePicker.OnTimeChangedListene
  9. android与j2me移植之clipRect

随机推荐

  1. Android(安卓)学习笔记——利用JNI技术在
  2. Android(安卓)无线接口层RIL(Radio Layer
  3. Andriod编程基础(一):Andriod的优势及光明
  4. Android(安卓)APK文件在电脑上面运行方法
  5. Android移动图片
  6. Android应用程序注册广播接收器(registerR
  7. 将tensorflow训练好的模型移植到android
  8. android 入门之一【开发环境搭建】
  9. Android应用程序注册广播接收器(registerR
  10. android内存处理机制