Format the output date on the page in asp.net

Source: Internet
Author: User
Tags datetime

The simplest way to write code on the page

The code is as follows: Copy code

% # Eval ("Fenddate", "{0: yyyy/MM/dd}") %>


At first, I wrote this on the program page.

The code is as follows: Copy code

String sDate = DateTime. now. year. toString () + DateTime. now. month. toString () + DateTime. now. day. toString () + DateTime. now. hour. toString () + DateTime. now. minute. toString () + DateTime. now. second. toString ()


Next we will summarize some information about the date formats in asp.net.

The code is as follows: Copy code

// Get date + time
DateTime. Now. ToString (); // 20:02:10
DateTime. Now. ToLocalTime (). ToString (); // 20:12:12

// Obtain the date
DateTime. Now. ToLongDateString (). ToString (); // September 4, 2008
DateTime. Now. Tow.datestring (). ToString (); //
DateTime. Now. ToString ("yyyy-MM-dd"); // 2008-09-04
DateTime. Now. Date. ToString (); // 0:00:00

// Obtain the time
DateTime. Now. ToLongTimeString (). ToString (); // 20:16:16
DateTime. Now. Tow.timestring (). ToString (); // 20: 16
DateTime. Now. ToString ("hh: mm: ss"); // 08:05:57
DateTime. Now. TimeOfDay. ToString (); // 20:33:50. 7187500

// Others
DateTime. ToFileTime (). ToString (); // 128650040212500000
DateTime. Now. ToFileTimeUtc (). ToString (); // 128650040772968750
DateTime. Now. ToOADate (). ToString (); // 39695.8461709606
DateTime. Now. ToUniversalTime (). ToString (); // 12:19:14

DateTime. Now. Year. ToString (); get Year // 2008
DateTime. Now. Month. ToString (); get Month // 9
DateTime. Now. DayOfWeek. ToString (); get the week // Thursday
DateTime. Now. DayOfYear. ToString (); get the day // 248
DateTime. Now. Hour. ToString (); get Hour // 20
DateTime. Now. Minute. ToString (); get Minute // 31
DateTime. Now. Second. ToString (); get seconds // 45

// N is a number, which can be an integer or decimal number.
Dt. AddYears (n). ToString (); // time plus n years
Dt. AddDays (n). ToString (); // add n days
Dt. AddHours (n). ToString (); // add n hours
Dt. AddMonths (n). ToString (); // add n months
Dt. AddSeconds (n). ToString (); // add n seconds
Dt. AddMinutes (n). ToString (); // add n points

Related Article

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.