Есть ли аналог DateTime из Java - C#
Формулировка задачи:
Подскажите эквивалент этому методу из Java для c#:
Не знаю какие классы будут равнозначны ZonedDateTime и методы типа toInstant().atZone. а так же between
public long monthlyPremium() {
ZonedDateTime dateTime = getEmploymentDate().toInstant().atZone(ZoneId.systemDefault());
long years = ChronoUnit.YEARS.between(dateTime, ZonedDateTime.now());
long premium = years / 20;
if (dateTime.getMonth() == dateTime.getMonth().JANUARY) {
premium += getSalary();
}
System.out.print(premium);
return premium;
}
public void up(){}
Решение задачи: «Есть ли аналог DateTime из Java»
textual
Листинг программы
long monthlyPremium() {
DateTime emplDate = getEmploymentDate().ToUniversalTime().Add(TimeZoneInfo.Local.BaseUtcOffset);
int years = YearsBeetween(emplDate, DateTime.Now);
long premium = years / 20;
if (emplDate.Month == 1) {
premium += getSalary();
}
Console.WriteLine(premium);
return premium;
}
static int YearsBeetween(DateTime d1, DateTime d2)
{
DateTime zeroTime = new DateTime(1, 1, 1);
TimeSpan span = d2 - d1;
return (zeroTime + span).Year - 1;
}