DateTime in JS, C #, and SQL

Source: Internet
Author: User
Tags getdate

One: Datatime in SQL

1. Between and equals >= and <=

2. Commonly used methods of querying datatime into strings

Select CONVERT (varchar), GETDATE (), at $)://YYYY-MM-DD

Select CONVERT (varchar), GETDATE (), ()://Yyyy-mm-dd HH:MM:SS

Select CONVERT (varchar), GETDATE (), 111)://YYYY/MM/DD

Select CONVERT (varchar), GETDATE (),//YYYYMMDD):

Second: JS in the Datatime

1. Build time: Var a=new Date (YYYY,MM,DD,HH,MM,SS)

Return value: Week m+1 D HH:mm:ss utc+0800 yyyy

(if D exceeds the number of days of the month m+1, the m+2 month is returned as D minus the number of m+1 months)

New Date (n);

n is the number of milliseconds from January 1, 1970

The return value is-week 1 HH:mm:ss utc+0800 yyyy

2. Get time: var mydate = new Date ();

var year=mydate.getyear (); Get Current year (2-bit)

var year1=mydate.getfullyear (); Get the full year (4-bit, 1970)

var moonth=mydate.getmonth (); Get the current month (0-11, 0 for January)

Mydate.getdate (); Get current day (1-31)

Mydate.getday (); Get Current week x (0-6, 0 for Sunday)

Mydate.gettime (); Gets the current time (the number of milliseconds since 1970.1.1)

Mydate.gethours (); Get current number of hours (0-23)

Mydate.getminutes (); Gets the current number of minutes (0-59)

Mydate.getseconds (); Gets the current number of seconds (0-59)

Mydate.getmilliseconds (); Gets the current number of milliseconds (0-999)

Mydate.tolocaledatestring (); Get current date yyyy m month D Day

Mydate.tolocaletimestring (); Get current Time HH:mm:ss

Mydate.tolocalestring (); Get date and time yyyy m month D Day HH:mm:ss

3. Parameter types supported by the Date.parse method and returned result types

(a static method of a Date object that "parses a string containing a date and returns the number of milliseconds between that date and midnight January 1, 1970.") )

A.date.parse ("Yyyy-mm-dd")
On IE and Mozilla:nan

B.date.parse ("mm-dd-yyyy")
On IE: The number of milliseconds from January 1, 1970
On Mozilla:nan "

C.date.parse ("mm/dd/yyyy")
Date.parse ("Yyyy/mm/dd")
On IE and Mozilla: Number of milliseconds from January 1, 1970

Three: DateTime in C #

1. This week

(to know that the first day of the week is the day of the week and that the first day of the week is a few days ago, it is important to note that every week from Sunday to Saturday)
DateTime.Now.AddDays (Convert.todouble (0-convert.toint16 (DateTime.Now.DayOfWeek))). ToShortDateString ();

DateTime.Now.AddDays (Convert.todouble (6-convert.toint16 (DateTime.Now.DayOfWeek))). ToShortDateString ();

2. This month

(The first day of the month is definitely number 1th, and the last day is the next month, minus another day)

DateTime.Now.Year.ToString () + DateTime.Now.Month.ToString () + "1"; First day

DateTime.Parse (DateTime.Now.Year.ToString () + DateTime.Now.Month.ToString () + "1"). AddMonths (1). AddDays (-1). ToShortDateString ();//Last Day

It's easier to use ToString's character formatting in C #

DateTime.Now.ToString ("yyyy-mm-01");

DateTime.Parse (DateTime.Now.ToString ("yyyy-mm-01")). AddMonths (1). AddDays (-1). ToShortDateString ();

3. The quarter

(A lot of people will feel the difficulty here, need to write a long process to judge.) In fact, we all know that four quarters a year, a quarter of three months)

First we push the date to the first month of the quarter, and then the first day of the month is the first day of the quarter.

DateTime.Now.AddMonths (0-((datetime.now.month-1)% 3)). ToString ("yyyy-mm-01");

Similarly, the last day of the quarter is the first day of the next quarter minus one

DateTime.Parse (DateTime.Now.AddMonths (3-((datetime.now.month-1)% 3)). ToString ("yyyy-mm-01")). AddDays (-1). ToShortDateString ();

4. This year

DateTime.Parse (DateTime.Now.ToString ("yyyy-01-01")). ToShortDateString ();

DateTime.Parse (DateTime.Now.ToString ("yyyy-01-01")). AddYears (1). AddDays (-1). ToShortDateString ();

5. Various formats

A. with the. toString ("" Yyyy-mm-dd ") of the DateTime class,

B. Convert date display format by String class: String.Format ("Yyyy-mm-dd", yourdatetime);

However, if the " Regional and Language Settings " option on your computer is selected in Simplified Chinese, you will find that it doesn't work when you format 2008-09-09 with ToString ("Yyyy/mm/dd")!

What is this for? The reason is that under current culture (ZH-CN), DateTime dateseparator is-not/. Then we add a parameter to the ToString method: System.Globalization.DateTimeFormatInfo.InvariantInfo, the system will be completely in accordance with the custom format to output!

C. DateTime dt = new datetime (yyyy, M, D, H,m, s);//yyyy-mm-dd HH:mm:ss

String.Format ("{0:y yy yyy yyyy}", DT); "8 008" year
String.Format ("{0:m MM MMM MMMM}", DT); "3 Mar March" month
String.Format ("{0:d dd ddd dddd}", DT); "9 Sun Sunday" Day
String.Format ("{0:h hh H hh}", DT); "4" Hour 12/24
String.Format ("{0:m mm}", DT); "5" Minute
String.Format ("{0:s ss}", DT); "7" second
String.Format ("{0:f ff FFF FFFF}", DT); "1 123 1230" Sec.fraction
String.Format ("{0:f FF FFF FFFF}", DT); "1 123 123" without zeroes
String.Format ("{0:t tt}", DT); "P PM" a.m. or p.m.
String.Format ("{0:z zz zzz}", DT); " -6-06-06:00" time zone

6.

Note:

GMT is the abbreviation for "Greenwich Mean Time", which is called "GMT" and is the standard time of the United Kingdom and a reference standard for time around the world. The standard time difference between China and Britain is 8 hours, that is, the UK is 8 hours behind the time in Beijing.

BST is the abbreviation for "British Summer time", which means "UK daylight saving Time" is one hour faster than GMT, starting from the end of March and ending at the end of October. During daylight saving time, the difference between China and Britain is 7 hours.

DateTime in JS, C #, and SQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.