Java has Calendar Class, but C# doesn't. How to implement the below Java function in C#?
//获得从昨天开始的时间 in Java
public static long yesterdayBeginTime() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTimeInMillis();
}
Already answered you in your other post http://segmentfault.com/q/1010000003707587
The main reason is that the time representation of C# and Java is a little different
C# uses Tick (100 nanoseconds), Java uses milliseconds.
C# starts from 0001-1-1, Java starts from 1970-1-1
So conversion is required. The following two conversion methods are codes copied from Viti.Util