Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handling Date/Time values
Message
De
23/08/2005 05:17:55
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01042832
Message ID:
01042836
Vues:
17
>can you elaborate further (please present several examples) thanks
using System;
class Test
{
 static void Main()
 {
	DateTime dt = DateTime.Now;
	Console.WriteLine("Now is: {0}", dt);
	Console.WriteLine("Ticks since 1/1/0001 12:00 AM is: {0}",dt.Ticks);
	Console.WriteLine("{0} + {1} years = {2}",dt,       5,dt.AddYears(5));
	Console.WriteLine("{0} + {1} months = {2}",dt,      5,dt.AddMonths(5));
	Console.WriteLine("{0} + {1} days = {2}",dt,        5,dt.AddDays(5));
	Console.WriteLine("{0} + {1} hours = {2}",dt,       5,dt.AddHours(5));
	Console.WriteLine("{0} + {1} minutes = {2}",dt,     50,dt.AddMinutes(50));
	Console.WriteLine("{0} + {1} seconds = {2}",dt,     1800,dt.AddSeconds(1800));
	Console.WriteLine("{0} + {1} milliseconds = {2}",dt,18000,dt.AddMilliseconds(18000));
	Console.WriteLine("{0} + {1} ticks = {2}",dt,       36000000,dt.AddTicks(36000000));

	TimeSpan ts = dt.TimeOfDay;
        Console.WriteLine("Midnight using timespan: {0}",dt.Subtract(ts));
        Console.WriteLine("Midnight for tonight using timespan: {0}",dt.Subtract(ts).AddDays(1));

	DateTime dt1 = new DateTime(2000,2,29);
	DateTime dt2 = new DateTime(2000,3,1);

	Console.WriteLine("Dt1 is: {0}",dt1);
	Console.WriteLine("Dt2 is: {0}",dt2);

        TimeSpan ts1 = dt2-dt1;
        Console.WriteLine("Dt2 - Dt1 is: {0}",ts1);

        Console.WriteLine("Dt2 + 2 days 10 hours 15 mins and 30 seconds is: {0}",
            dt2+new TimeSpan(2,10,15,30));
 }
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform