How to create array of TimeZone objects in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    public class TimeZoneClass
    {
        private DateTimeOffset dt;
        private TimeZoneInfo tz;
        
        public TimeZoneClass(DateTimeOffset dateTime, TimeZoneInfo timeZone)
        {
            dt = dateTime;
            tz = timeZone;
        }

        public DateTimeOffset DateTime
        {
            get { return dt; }
        }

        public TimeZoneInfo TimeZone
        {
            get { return tz; }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            TimeZoneClass[] timeZoneObjects = { new TimeZoneClass(DateTime.Now, TimeZoneInfo.Local),
                                                new TimeZoneClass(DateTime.Now, TimeZoneInfo.Utc) };

            foreach (var timeZoneO in timeZoneObjects)
                Console.WriteLine("{0}: {1:G}",
                                   timeZoneO.TimeZone == null ? "<null>" : timeZoneO.TimeZone.ToString(),
                                   timeZoneO.DateTime);
        }
    }
}


/*
run:
 
(UTC+02:00) Jerusalem: 12-4-16 7:52:18 AM
UTC: 12-4-16 7:52:18 AM

*/

 



answered Apr 12, 2016 by avibootz

Related questions

1 answer 225 views
1 answer 152 views
152 views asked Apr 12, 2016 by avibootz
1 answer 161 views
1 answer 135 views
3 answers 87 views
2 answers 162 views
162 views asked Aug 5, 2022 by avibootz
...