mercredi 21 août 2019

I want to get how far ahead/behind of my local time information with the help of FindTimeZoneById

For example, when informations for Berlin came, also I want to get +2 hour further or -2 hour behind infos. My controller is:

            var worldClocks = db.WorldClockItem.ToList();  
            var result = new WorldClockForListDto();
            result.WorldClocks= new List<WorldClockForListDto>();

                foreach (var worldClock in worldClocks)
               {
                    TimeZoneInfo timeZoneInfo;
                    timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(worldClock.timeZone.ToString());

                result.WorldClocks.Add(new WorldClockForListDto
                {
                    locationName = worldClock.locationName,
                    date = TimeZoneInfo.ConvertTime(DateTime.Now, timeZoneInfo).ToShortDateString(),
                    time = TimeZoneInfo.ConvertTime(DateTime.Now, timeZoneInfo).ToShortTimeString(),
                    day = TimeZoneInfo.ConvertTime(DateTime.Now, timeZoneInfo).ToLongDateString().Split(',')[0]
                });                

            }
            return Ok(result);
        }




Aucun commentaire:

Enregistrer un commentaire