For my Java to C# conversion project, I need to use something equivalent to Java's Calender class. I have some codes like:

Calender cal = Calender.getInstance();
long time = Calendar.getInstance().getTime().getTime();
long time2 = System.currentTimeMillis();

which returns some random values at different times. I have come to know C-sharp's DateTime is the closest to this Calender class, but DateTime's Tick property does not give exactly the similar result.

What will be my required code snippet here to get my desired output?

Recommended Answers

All 2 Replies

I have found a code snippet that solves the System.currentTimeMillis() method's purpose.

public static long CurrentTimeMillis()
{
    DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local);
    return (long) (DateTime.Now - Jan1st1970).TotalMilliseconds;
}

Still need help on Calender.getInstance() method, please help.

This will get you started.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.