Você está na página 1de 4

2/2/2016 FormatsforDateTime.

ToString()CodeProject

12,055,807 members 61,521 online Sign in

Searchforarticles,questions,tips
articles Q&A forums lounge

Formats for DateTime.ToString


S.Vinothkumar, 20 Jul 2007 Rate this:
2.55 28 votes

Formats for DateTime.ToString

Introduction
Here is the lot of formats are given for how to use the DateTime.ToString in our C# Project.

Background
The DateTime class is most usefull for our time based programs. But we dont' know how to use the DateTime.ToString
function with appropriate formats. Here I am giving some formats for using DateTime.ToString.

Using the code


In our C# Program, we should declare the datetime and write the code as follows,

The result also given in right side...

Hide Shrink Copy Code


//
//Anysourcecodeblockslooklikethis
//

DateTimedt=DateTime.Now;
StringstrDate="";
strDate=dt.ToString("MM/dd/yyyy");//07/21/2007
strDate=dt.ToString("dddd,ddMMMMyyyy");//Saturday,21July2007
strDate=dt.ToString("dddd,ddMMMMyyyyHH:mm");//Saturday,21July200714:58
strDate=dt.ToString("dddd,ddMMMMyyyyhh:mmtt");//Saturday,21July200703:00PM
strDate=dt.ToString("dddd,ddMMMMyyyyH:mm");//Saturday,21July20075:01
strDate=dt.ToString("dddd,ddMMMMyyyyh:mmtt");//Saturday,21July20073:03PM
strDate=dt.ToString("dddd,ddMMMMyyyyHH:mm:ss");//Saturday,21July200715:04:10
strDate=dt.ToString("MM/dd/yyyyHH:mm");//07/21/200715:05
strDate=dt.ToString("MM/dd/yyyyhh:mmtt");//07/21/200703:06PM
strDate=dt.ToString("MM/dd/yyyyH:mm");//07/21/200715:07
strDate=dt.ToString("MM/dd/yyyyh:mmtt");//07/21/20073:07PM
strDate=dt.ToString("MM/dd/yyyyHH:mm:ss");//07/21/200715:09:29
strDate=dt.ToString("MMMMdd");//July21
strDate=dt.ToString("yyyy''MM''dd'T'HH':'mm':'ss.fffffffK");//200707
21T15:11:19.1250000+05:30

http://www.codeproject.com/Articles/19677/FormatsforDateTimeToString 1/4
2/2/2016 FormatsforDateTime.ToString()CodeProject
strDate=dt.ToString("ddd,ddMMMyyyyHH':'mm':'ss'GMT'");//Sat,21Jul200715:12:16GMT
strDate=dt.ToString("yyyy''MM''dd'T'HH':'mm':'ss");//20070721T15:12:57
strDate=dt.ToString("HH:mm");//15:14
strDate=dt.ToString("hh:mmtt");//03:14PM
strDate=dt.ToString("H:mm");//5:15
strDate=dt.ToString("h:mmtt");//3:16PM
strDate=dt.ToString("HH:mm:ss");//15:16:29
strDate=dt.ToString("yyyy''MM''ddHH':'mm':'ss'Z'");//2007072115:17:20Z
strDate=dt.ToString("dddd,ddMMMMyyyyHH:mm:ss");//Saturday,21July200715:17:58
strDate=dt.ToString("yyyyMMMM");//2007July

Hencewecanformatandgettingthedatetimevalue.

License
This article has no explicit license attached to it but may contain usage terms in the article text or the download files
themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share
EMAIL TWITTER

About the Author


S.Vinothkumar
Web Developer
India

Hi Viewers,

I wish to all. This is Vinoth. This is where I try to condense everything that you need to know about me.

Blog:

visit my blog

Interests:

I'm passionate about a great many things and continually learning about the things that interest me. They are wearable
computers, User Interface Design, Artificial life, Industrial music.

http://www.codeproject.com/Articles/19677/FormatsforDateTimeToString 2/4
2/2/2016 FormatsforDateTime.ToString()CodeProject

You may also be interested in...


Formatting a DateTime for Intel IoT Gateways:
display format string Publishing Data to an MQTT
description Broker Using Python

DataGrid Formatting HowTo Intel IoT Code


Samples: Smart Stove Top

The .NET File Format Intel IoT Gateway: Windows


10 Getting Started Guide

Comments and Discussions


You must Sign In to use this message board.

Search Comments Go

First Prev Next

Message Automatically Removed


18Apr14 1:31

My vote of 3
Yogesh Potdar 14May13 1:30

My vote of 3
d347hm4n 26Jun12 6:46

My vote of 1
Member 7823211 27Apr12 1:52

My vote of 1
VMykyt 16Jul09 21:54

Easy for the Lazy


hairry_p0tter 14Oct08 2:32

Unnecessary apostrophes
PIEBALDconsult 21Jul07 10:11

Really!?
Mark Nischalke 21Jul07 9:35

http://www.codeproject.com/Articles/19677/FormatsforDateTimeToString 3/4
2/2/2016 FormatsforDateTime.ToString()CodeProject

Better Reference at Geekzilla


delyk 21Jul07 8:35

Why?
mav.northwind 21Jul07 8:29

Refresh 1

General News Suggestion Question Bug Answer Joke Praise Rant


Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile


Select Language

Web01 | 2.8.160115.1 | Last Updated 21 Jul 2007
Layout: fixed | fluid Article Copyright 2007 by S.Vinothkumar
Everything else Copyright CodeProject, 19992016

http://www.codeproject.com/Articles/19677/FormatsforDateTimeToString 4/4

Você também pode gostar