Csharp/CSharp Tutorial/Date Time/DateTime Now — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 12:20, 26 мая 2010

Check the current second

using System;
    class MainClass
    {
        static void Main(string[] args)
        {
            int sec = -1;
            while( DateTime.Now.Second != 0 )
            {
                if( sec != DateTime.Now.Second )
                {
                    sec = DateTime.Now.Second;
                    Console.Write( "...{0}", 60-DateTime.Now.Second );
                }
            }
        }
    }

Extracting the current date/time: Now and UtcNow

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Security.Cryptography;
public class MainClass
{
    public static void Main()
    {
        DateTime localNow = DateTime.Now;
        Console.WriteLine("{0} - {1} ({2})", localNow, localNow.Kind,
            TimeZone.CurrentTimeZone.StandardName);
        DateTime utcNow = DateTime.UtcNow;
        Console.WriteLine("{0} - {1}", utcNow, utcNow.Kind);
    }
}

Get current time

using System;  
  
class MainClass {  
  public static void Main() {  
    string t; 
    int seconds; 
 
    DateTime dt = DateTime.Now; 
    seconds = dt.Second; 
 
    // update time if seconds change 
    if(seconds != dt.Second) { 
      seconds = dt.Second; 
 
      t = dt.ToString("T"); 
      Console.WriteLine(t); 
    } 
  } 
}