码迷,mamicode.com
首页 > Web开发 > 详细

JS实用小函数 数据是否合法或存在 获取当前日期时间

时间:2018-06-22 16:33:49      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:判断   color   data   get   not   格式   for   format   name   

 

1、判断数据是否合法或存在

//判断数据是否合法或存在
function isNotNull(data)
{
  if(data === "" || data === undefined || data === null)  //此处用绝对等于,保证数据类型及数据完全一致。根据需要选为“==”
    return false;
  else
    return true;
}

2、获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS”

//获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS”
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
    return currentdate;
}

JS实用小函数 数据是否合法或存在 获取当前日期时间

标签:判断   color   data   get   not   格式   for   format   name   

原文地址:https://www.cnblogs.com/dyhao/p/9213761.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!