js 获取当前时间--年月日时分秒,js 对象转数组

前言


在这里我只是记录一下方法,至于放在全局的就不写了,如何改成全局的方法,详情请移步关于vue全局引用公共的js和公共的组件的折腾

直接上代码

  mounted() {
    //获取当前时间
    let _currentTime = this.getNowFormatDate();
              console.log(_currentTime);
},
  methods: {
  getNowFormatDate() {
      var date = new Date();
      var hengGang = "-";
      var maoHao = ":";
      var month = date.getMonth() + 1;
      var curDate = date.getDate();
      var curHours = date.getHours();
      var curMinutes = date.getMinutes();
      var curSeconds = date.getSeconds();

      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (curDate >= 0 && curDate <= 9) {
        curDate = "0" + curDate;
      }
      if (curHours >= 0 && curHours <= 9) {
        curHours = "0" + curHours;
      }
      if (curMinutes >= 0 && curMinutes <= 9) {
        curMinutes = "0" + curMinutes;
      }
      if (curSeconds >= 0 && curSeconds <= 9) {
        curSeconds = "0" + curSeconds;
      }

      // var currentdate = date.getFullYear() + hengGang + month + hengGang + curDate
      //         + " " + curHours + maoHao + curMinutes
      //         + maoHao + curSeconds;
      var currentdate =
        curHours + maoHao + curMinutes + maoHao + curSeconds;
      return currentdate;
    },
}


js 对象转数组
  let obj = {
      name1:'张三',
      name2:'李四',
      name3:'王五',
   }
let arr = Object.values(obj);
console.log(arr)

结束语

没得结束语,哈哈哈

你可能感兴趣的:(js 获取当前时间--年月日时分秒,js 对象转数组)