简体   繁体   中英

Convert string into datetime in razor view with javascript?

In my controller I convert the datetime into string

here's the code

var result = from c in displayedCustomers select new[] { c.NonActiveDate.ToString("dd-MM-yyyy HH:mm:ss")};

and I want to convert it back to datetime cause I want to compare it with today date

this is my code and not working cause the string cannot be compare with date

if (d <= Date.now)
{
    return '<span style = "color : red">' + oObj.aData[4]+ '</span>';
}

cant you fill another string with the date time now and compare them that way.

    {
            var time = DateTime.Now;

            string Time = time.ToString();

           if(yourtimevariable == Time)
           {
            //enter what you want to do when the if statement is true
           }
    }

Convert your string to Date object in java script using "Date" function before comparing

if(new Date("your date string") <= Date.now)
{
    // your code
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM