您当前的位置: 首页 > 

仙剑情缘

暂无认证

  • 0浏览

    0关注

    333博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

安卓UTC与时间日期互转方法

仙剑情缘 发布时间:2020-08-09 14:47:28 ,浏览量:0

  • 获取时区
 public static long getGmtTimeZone() {
        long _t = TimeZone.getDefault().getOffset(System.currentTimeMillis()) / (3600 * 1000);
        return _t;
    }
  • UTC毫秒转时间日期格式
public static String longtransformstring(Long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH点mm分ss秒");

        Date dt = new Date(time);
        String stime = sdf.format(dt);
        return stime;

    }
  • 时间日期转UTC秒
 public static long date_to_utc(int y,int m,int d,int h,int min,int sec){
        Calendar calendar = Calendar.getInstance();
        calendar.set(y,m-1,d,h,min,sec);
        long timezone = getGmtTimeZone();
        long time = calendar.getTimeInMillis()/1000+timezone*3600;
        Log.i("TEST12", "set_alarm_time: " +time);
        return time;
    }
 

 

 

 

关注
打赏
1658017818
查看更多评论
立即登录/注册

微信扫码登录

0.0358s