How to display date and time through java script and C# code.

 Fetching system’s date and next two months date and displaying it in two different text boxes.

C#:     

Through c# ‘DateTime’ function fetches system’s current date. In given scenario two strings are storing data in ‘mm/dd/yyyy’ format and second string stores todays next two months date.

            string expiryDateFrom = DateTime.Now.ToString("MM/dd/yyyy");
            string expiryDateTo =  DateTime.Today.AddMonths(2).ToString("MM/dd/yyyy");

Java Script:  

Through java script ‘getDate’,’getMonth’,’getFullYear’ are responsible for respectively fetching data for day,month,and for year.here month month is fetching current month while month1 fetching todays next two month.
For example if month =03 then month1 will be month1 = 05.

function displayDate() {
            var now = new Date();
            var day = ("0" + now.getDate()).slice(-2);
            var month = ("0" + (now.getMonth() + 1)).slice(-2);
            var month1 = ("0" + (now.getMonth() + 3)).slice(-2);
            var fromDate = (month) + "/" + (day) + "/" + now.getFullYear();
            var ToDate = (month1) + "/" + (day) + "/" + now.getFullYear();
            document.getElementById("pagecontent_cphBody_txtExpiryDateFrom").value = fromDate;
            document.getElementById("pagecontent_cphBody_txtExpiryDateTo").value = ToDate;
        }

Description: 
HeretxtExpiryDateFrom’ and ‘txtExpiryDateTo’ are two textbox that are displaying current date and next two months date.


Comments