Checking on Date and Time (C#)

Please support our C# advertiser: Intel Parallel Studio Home
vegaseat vegaseat is offline Offline Feb 9th, 2005, 12:30 pm |
0
Is it Mother Date and Father Time? Any way, getting all the different date and time displays working can be imperturbably perplexing at times. You take a look at it in this Windows Console Application.
Quick reply to this message  
C# Syntax
  1. // retrieve and format date/time data
  2. // tested with VCS.NET 2003
  3.  
  4. using System; // has all the date/time stuff
  5.  
  6. class myApp
  7. {
  8. public static void Main()
  9. {
  10. DateTime CurrTime = DateTime.Now;
  11.  
  12. Console.WriteLine("DateTime display listing specifier and result:\n");
  13.  
  14. Console.WriteLine("d = {0:d}", CurrTime ); // Short date mm/dd/yyyy
  15. Console.WriteLine("D = {0:D}", CurrTime ); // Long date day, month dd, yyyy
  16. Console.WriteLine("f = {0:f}", CurrTime ); // Full date/short time day, month dd, yyyy hh:mm
  17. Console.WriteLine("F = {0:F}", CurrTime ); // Full date/full time day, month dd, yyyy HH:mm:ss AM/PM
  18. Console.WriteLine("g = {0:g}", CurrTime ); // Short date/short time mm/dd/yyyy HH:mm
  19. Console.WriteLine("G = {0:G}", CurrTime ); // Short date/long time mm/dd/yyyy hh:mm:ss
  20. Console.WriteLine("M = {0:M}", CurrTime ); // Month dd
  21. Console.WriteLine("R = {0:R}", CurrTime ); // ddd Month yyyy hh:mm:ss GMT
  22. Console.WriteLine("s = {0:s}", CurrTime ); // yyyy-mm-dd hh:mm:ss can be sorted!
  23. Console.WriteLine("t = {0:t}", CurrTime ); // Short time hh:mm AM/PM
  24. Console.WriteLine("T = {0:T}", CurrTime ); // Long time hh:mm:ss AM/PM
  25. Console.WriteLine("u = {0:u}", CurrTime ); // yyyy-mm-dd hh:mm:ss universal/sortable
  26. Console.WriteLine("U = {0:U}", CurrTime ); // day, month dd, yyyy hh:mm:ss AM/PM
  27. Console.WriteLine("Y = {0:Y}", CurrTime ); // Month, yyyy
  28. Console.WriteLine();
  29. Console.WriteLine("DateTime.Month = " + CurrTime.Month); // number of month
  30. Console.WriteLine("DateTime.DayOfWeek = " + CurrTime.DayOfWeek); // full name of day
  31. Console.WriteLine("DateTime.TimeOfDay = " + CurrTime.TimeOfDay); // 24 hour time
  32.  
  33. // number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am
  34. // useful for time-elapsed measurements
  35. Console.WriteLine("DateTime.Ticks = " + CurrTime.Ticks);
  36.  
  37. Console.Read(); // wait
  38. }
  39. }
  40.  
0
dananos dananos is offline Offline | Mar 19th, 2007
It should be also mentioned that you can combine these as in

DateTime.Now.ToString("dd/MM/yyyy h:MM tt")

- for 13/12/2007 5:04 PM as an example

http://www.freebiesms.co.uk
 
0
hwa hwa is offline Offline | Mar 3rd, 2008
Hi,

May I know how to make the following comparison:

A(Date/Time) + B(Integer, in HOUR) <= C.



if after A+B is next day of the date A then is should be increase one day then only compare with C.

How can I make it !!

Thanks in advance
 
0
jakoo1983 jakoo1983 is offline Offline | Feb 11th, 2009
If Iwant Do that in Windows Form
//.................................
DateTime CurrTime = DateTime.Now;
t1.text=CurrTime;
 
 

Tags
date, format, time

Message:


Thread Tools Search this Thread



Tag cloud for date, format, time
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC