internal static void ClrTicksToJavaDate(java.util.Date d, long ticks) { long millis = ClrMillisToJavaMillis(ticks / TimeSpan.TicksPerMillisecond); d.setTime(millis); if (DEFAULT_TIME_ZONE.inDaylightTime(d)) { millis -= DEFAULT_TIME_ZONE.getDSTSavings(); d.setTime(millis); } }
/// <summary> /// Convert a DateTime instance to a Java Date instance. /// </summary> /// <param name="d">DateTime instance</param> /// <returns>Java Date instance</returns> public static java.util.Date ToJavaDate(this DateTime d) { TimeSpan ts = d - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime(); long timestamp = (long)ts.TotalMilliseconds; java.util.TimeZone tz = java.util.TimeZone.getDefault(); java.util.Date result = new java.util.Date(timestamp - tz.getRawOffset()); if (tz.inDaylightTime(result) == true) { int savings = tz.getDSTSavings(); result = new java.util.Date(result.getTime() - savings); } return(result); }