コード例 #1
0
        public DateTimeAndZone GetUtcTimeZone(DateTime local, string state, string country)
        {
            var timeZone = GetTimeZoneInfo(state, country);

            if (timeZone == null)
            {
                return(null);
            }
            return(DateTimeAndZone.FromLocal(local, timeZone));
        }
コード例 #2
0
        public static DateTimeAndZone FromLocal(DateTime local, TimeZoneInfo timeZone)
        {
            if (local.Kind == DateTimeKind.Utc)
            {
                throw new ArgumentException("DateTime utc must be .Kind == DateTimeKind.Unspecified, not Utc.", "local");
            }

            // We need to push this date from Local (default for Parse) to Unspecified because it's outside
            // the limited timezone space the DateTime structure understands (Local, UTC, and go fish)
            if (local.Kind == DateTimeKind.Local)
            {
                local = DateTime.SpecifyKind(local, DateTimeKind.Unspecified);
            }

            var u = new DateTimeAndZone(TimeZoneInfo.ConvertTimeToUtc(local, timeZone), timeZone);

            return(u);
        }
コード例 #3
0
		public static DateTimeAndZone FromLocal(DateTime local, TimeZoneInfo timeZone)
		{
			if (local.Kind == DateTimeKind.Utc)
				throw new ArgumentException("DateTime utc must be .Kind == DateTimeKind.Unspecified, not Utc.", "local");

			// We need to push this date from Local (default for Parse) to Unspecified because it's outside
			// the limited timezone space the DateTime structure understands (Local, UTC, and go fish)
			if (local.Kind == DateTimeKind.Local)
				local = DateTime.SpecifyKind(local, DateTimeKind.Unspecified);

			var u = new DateTimeAndZone(TimeZoneInfo.ConvertTimeToUtc(local, timeZone), timeZone);
			return u;
		}
コード例 #4
0
        public DateTimeAndZone GetUtcTimeZone(DateTime local, string state, string country, TimeZoneId defaultTimeZoneId)
        {
            var timeZone = GetTimeZoneInfo(state, country, defaultTimeZoneId);

            return(DateTimeAndZone.FromLocal(local, timeZone));
        }