asp.net acquisition date and time into the database

// get the date + time 
DateTime.Now.ToString (); // 2008-9-4 20:02:10 
DateTime.Now.ToLocalTime () ToString ();. // 2008-9-4 20:12:12
 // get the date 
DateTime.Now.ToLongDateString () ToString ();. // 2008 September 4 
DateTime.Now.ToShortDateString () ToString ();. // 2008-9-4 
DateTime.Now.ToString ( " the MM-dd-YYYY " ); // 2008-09-04 
DateTime.Now.Date.ToString (); // 2008-9-4 0:00:00
 // acquisition time 
DateTime.Now.ToLongTimeString () ToString. (); // 20:16:16
DateTime.Now.ToShortTimeString().ToString(); // 20:16
DateTime.Now.ToString("hh:mm:ss"); // 08:05:57
DateTime.Now.TimeOfDay.ToString(); // 20:33:50.7187500
//其他
DateTime.ToFileTime().ToString(); // 128650040212500000
DateTime.Now.ToFileTimeUtc().ToString(); // 128650040772968750
DateTime.Now.ToOADate().ToString(); // 39695.8461709606
DateTime.Now.ToUniversalTime().ToString(); // 2008-9-4 12:19:14
DateTime.Now.Year.ToString(); 获取年份 // 2008
DateTime.Now.Month.ToString (); Gets month // 9 
DateTime.Now.DayOfWeek.ToString (); Gets week // catalog on Thursday    
DateTime.Now.DayOfYear.ToString (); Get the first few days // 248 
DateTime.Now .Hour.ToString (); Get h // 20 is 
DateTime.Now.Minute.ToString (); Get min // 31 is 
DateTime.Now.Second.ToString (); Get the number of seconds // 45
 // n-is a number, may integer, decimal things can 
dt.AddYears (n) .ToString (); // time n plus years 
dt.AddDays (n) .ToString (); // add n days 
dt.AddHours (n) .ToString ( ); // add n h 
dt.AddMonths (n) .ToString (); // add n months
dt.AddSeconds (n) .ToString (); // add n seconds 
dt.AddMinutes (n) .ToString (); // add n points 
sql statement uses the function of the time and date 
getdate (): Get current system time 
DATEADD ( datepart, number, date): calculates a new time value increases at time after a time on the basis of, for example: DATEADD (YY, 30 , getdate ()) 
DATEDIFF (the datepart, StartDate, EndDate): calculating the difference between two times value, such as: DATEDIFF (YY, getdate (), ' 2008-08-08 ' ) 
DataName (the datepart, DATE): Gets the value of the different parts of the time, the return value is a string 
datepart (datepart, date): datename and similar, just return value integer 
day (date): Gets the specified time the number of days 
month (date): Gets the month specified time 
year (date): Gets the specified time of year 

to get the value of the week in English, but most people to convert Chinese
DateTime.Now.DayOfWeek.ToString (); // Thursday week acquired    

conversion:
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek)

一整条语句:

string filedate = DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Day.ToString() + "/" + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek) + "/" + DateTime.Now.ToString("hh:mm:ss");

Figure:

 

 If you have a better way to put time into the database, be sure to leave a message, we will study together ~~~

 

Guess you like

Origin www.cnblogs.com/maoye520/p/11525744.html