//var ShowLog = 1;
function getCurrentTime() {
  //获取当前时间
  var d = new Date();
  // 获取当前时区与UTC时间的分钟差值
  // const offset = d.getTimezoneOffset();
  const offset = 0;
  var diff_d = d.getTime();
  diff_d = diff_d + offset * 60 * 60 * 1000;
  var dateT = new Date(diff_d);
  //写入数据
  var weekName = new Array(
    "周日",
    "周一",
    "周二",
    "周三",
    "周四",
    "周五",
    "周六"
  );
  var dataMonth = dateT.getMonth();
  var dataDate = dateT.getDate();
  var weekDate = weekName[dateT.getDay()];
  dataMonth += 1;
  var tempstr1 = dataMonth + "/" + dataDate + " " + weekDate;

  // var hourdata = dateT.getUTCHours();
  // var secondData = dateT.getSeconds();
  var hourdata = "";
  var minutedata = "";
  var secondData = "";
  //   if (dateT.getUTCHours() < 10) hourdata = "0" + dateT.getUTCHours();
  //   else if (dateT.getUTCHours() >= 10 && dateT.getUTCHours() <= 24)
  //     hourdata = dateT.getUTCHours();
  //console.log("hour=" + dateT.getHours());
  hourdata = dateT.getHours().toString().padStart(2, "0");

  if (dateT.getMinutes() < 10) minutedata = "0" + dateT.getMinutes();
  else if (dateT.getMinutes() >= 10 && dateT.getMinutes() <= 60)
    minutedata = dateT.getMinutes();
  if (dateT.getSeconds() < 10) secondData = "0" + dateT.getSeconds();
  else if (dateT.getSeconds() >= 10 && dateT.getSeconds() <= 60)
    secondData = dateT.getSeconds();
  //合成字符串
  var tempstr2 = "";
  // tempstr2 = hourdata + ":" + minutedata;
  tempstr2 = hourdata + ":" + minutedata + ":" + secondData;
  // //console.log("tempstr1=" + tempstr1);
  // //console.log("tempstr2=" + tempstr2);
  tempstr1 = tempstr1 + " " + tempstr2;
  // //console.log("tempstr1+tempstr2=" + tempstr1);
  //更新时间字符串
  var obj = {
    // "dataHours": dataHours,
    // "dataMinutes": dataMinutes,
    // "dataSeconds": dataSeconds,
    // "dataweekday": tempstr,
    // "weekDate": weekDate,
    tempstr1: tempstr1,
    tempstr2: tempstr2,
  };

  return tempstr1;
}

// //console.log(getCurrentTime());

function setCurrentTime(obj) {
  //设置当前时间
  //写入数据
  var weekName = new Array(
    "周日",
    "周一",
    "周二",
    "周三",
    "周四",
    "周五",
    "周六"
  );
  var dataMonth = obj.mon;
  var dataDate = obj.day;
  var weekDate = weekName[obj.week];
  // dataMonth += 1;
  var tempstr1 = dataMonth + " / " + dataDate + " " + weekDate;

  var hourdata = "";
  var minutedata = "";
  var secondData = "";
  if (obj.hour < 10) hourdata = "0" + obj.hour;
  else hourdata = obj.hour;
  if (obj.min < 10) minutedata = "0" + obj.min;
  else minutedata = obj.min;
  if (obj.sec < 10) secondData = "0" + obj.sec;
  else secondData = obj.sec;
  //合成字符串
  var tempstr2 = "";
  tempstr2 = hourdata + ":" + minutedata;
  // tempstr2 = hourdata + ":" + minutedata + ":" + secondData;
  //更新时间字符串
  var obj = {
    tempstr1: tempstr1,
    tempstr2: tempstr2,
  };
  return obj;
}

module.exports = {
  getCurrentTime: getCurrentTime,
  setCurrentTime: setCurrentTime,
};
