Date and time accessing in c#

Hi,
I am getting error while retrieving date and time in C#

in java script I have used this code.

string monthVar = System.DateTime.Now.get_Month();
print(monthVar);

plz help me

string monthVar = System.DateTime.Now.ToString(“yyyy/MM/dd hh:mm:ss”);
print(monthVar);

:slight_smile:

In C# you have a “Month” property for the DateTime object that is equivalent to javascript’s get_Month() method, except that in C# it will return a month from 1-12 and in javascript 0-11. If you’re ok with 1-12 simply use:

string monthVar = System.DateTime.Now.Month.ToString();

And if you want 0-11 like javascript, use:

string monthVar = (System.DateTime.Now.Month - 1).ToString();