package com.example.jhpapp.utils;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import java.util.Calendar;
import java.util.Date;

/**
 * 湖北普瑞设置设备时间
 * ByYQL
 * Create：2023-5-6
 */
public class DeviceSetTime {
    public static void setSystemTime(Context context, long time) {
        //设置系统时间
        //2019年11月26日  01:02：23 long time = 1598233402000L;
        Log.i("setSystemTime",  "setSystemTime0:"+time);
        try {
            Log.i("setSystemTime","setSystemTime1:"+time);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date(time));
            Intent mIntent = new Intent("mmi.set.system.time");
            mIntent.putExtra("year", String.valueOf(calendar.get(Calendar.YEAR)));//年份要写全，例如 2018，不能写成18
            mIntent.putExtra("month", String.valueOf(calendar.get(Calendar.MONTH) + 1));
            mIntent.putExtra("day", String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
            mIntent.putExtra("hour", String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)));//传入的时间是24小时制的时间
            mIntent.putExtra("min", String.valueOf(calendar.get(Calendar.MINUTE)));
            mIntent.putExtra("second", String.valueOf(calendar.get(Calendar.SECOND)));
            context.sendBroadcast(mIntent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
