using System; public class MainClass { public static void Main() { TimeZone zone = TimeZone.CurrentTimeZone; DateTime dt1 = new DateTime(2008, 1, 1); DateTime dt2 = new DateTime(2008, 6, 1); Console.WriteLine(zone.IsDaylightSavingTime(dt1)); Console.WriteLine(zone.IsDaylightSavingTime(dt2)); Console.WriteLine(zone.GetUtcOffset(dt1)); Console.WriteLine(zone.GetUtcOffset(dt2)); } }
Author: coder
Initalize a timespan to 25 milliseconds
using System; public class ToString { public static void Main() { TimeSpan span; span = new TimeSpan(0, 0, 0, 0, 25); } }
Display the properties for myTimeSpan
using System; class MainClass { public static void Main() { int hours = 4; int minutes = 12; int seconds = 10; int days = 1; int milliseconds = 20; long ticks = 300; TimeSpan myTimeSpan = new TimeSpan(ticks); Console.WriteLine("myTimeSpan4 = " + myTimeSpan); Console.WriteLine("myTimeSpan.Days = " + myTimeSpan.Days); Console.WriteLine("myTimeSpan.Hours = " + myTimeSpan.Hours); Console.WriteLine("myTimeSpan.Minutes = " + myTimeSpan.Minutes); Console.WriteLine("myTimeSpan.Seconds = " + myTimeSpan.Seconds); Console.WriteLine("myTimeSpan.Milliseconds = " + myTimeSpan.Milliseconds); Console.WriteLine("myTimeSpan.Ticks = " + myTimeSpan.Ticks); Console.WriteLine("myTimeSpan.TotalDays = " + myTimeSpan.TotalDays); Console.WriteLine("myTimeSpan.TotalHours = " + myTimeSpan.TotalHours); Console.WriteLine("myTimeSpan.TotalMinutes = " +myTimeSpan.TotalMinutes); Console.WriteLine("myTimeSpan.TotalSeconds = " + myTimeSpan.TotalSeconds); Console.WriteLine("myTimeSpan.TotalMilliseconds = " + myTimeSpan.TotalMilliseconds); } }
Create a TimeSpan instance, specifying the number of ticks
using System; class MainClass { public static void Main() { int hours = 4; int minutes = 12; int seconds = 10; int days = 1; int milliseconds = 20; long ticks = 300; TimeSpan myTimeSpan4 = new TimeSpan(ticks); Console.WriteLine("myTimeSpan4 = " + myTimeSpan4); } }
Create a TimeSpan instance, specifying the days, hours, minutes, seconds, and milliseconds
using System; class MainClass { public static void Main() { int hours = 4; int minutes = 12; int seconds = 10; int days = 1; int milliseconds = 20; TimeSpan myTimeSpan3 = new TimeSpan(days, hours, minutes, seconds, milliseconds); Console.WriteLine("myTimeSpan3 = " + myTimeSpan3); } }
Create a TimeSpan instance, specifying the days, hours, minutes, and seconds
using System; class MainClass { public static void Main() { int hours = 4; int minutes = 12; int seconds = 10; int days = 1; TimeSpan myTimeSpan2 = new TimeSpan(days, hours, minutes, seconds); Console.WriteLine("myTimeSpan2 = " + myTimeSpan2); } }
Create a TimeSpan instance, specifying the hours, minutes, and seconds
using System; class MainClass { public static void Main() { int hours = 4; int minutes = 12; int seconds = 10; TimeSpan myTimeSpan = new TimeSpan(hours, minutes, seconds); Console.WriteLine("myTimeSpan = " + myTimeSpan); } }