如何确定空值日期为返回日期12-31-1969 [英] How to fix null value date is returning date 12-31-1969

查看:183
本文介绍了如何确定空值日期为返回日期12-31-1969的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

myObj = function MyObject(r) {
        this.Prop = r.Prop
        this.LogIn = new Date(r.LogIn)
        this.Created_Date = new Date(r.Created_Date)
    }

How do I assign empty value "" if r.LogIn is null otherwise Date.

Right now if LogIn is null, its assigning it to date 12-31-1969. 



我尝试过的事情:



What I have tried:

myObj = function MyObject(r) {
        this.Prop = r.Prop
        this.LogIn = function(r){
		       if(r.LogIn ==null){
		           return "";
		       }
		     else{
		      return new Date(r.LogIn);
		     }
        this.Created_Date = new Date(r.Created_Date)
    }

推荐答案

尝试以下操作:
Try this:
this.LogIn = r.LogIn ? new Date(r.LogIn) : "";


条件(三元)运算符-JavaScript | MDN [ ^ ]


Conditional (ternary) Operator - JavaScript | MDN[^]


这篇关于如何确定空值日期为返回日期12-31-1969的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆