
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
String format for DateTime in C#
Format DateTime using String.Format method.
Let us see an example −
Example
using System; static class Demo { static void Main() { DateTime d = new DateTime(2018, 2, 8, 12, 7, 7, 123); Console.WriteLine(String.Format("{0:y yy yyy yyyy}", d)); Console.WriteLine(String.Format("{0:M MM MMM MMMM}", d)); Console.WriteLine(String.Format("{0:d dd ddd dddd}", d)); } }
Above we have first set the DateTime class object −
DateTime d = new DateTime(2018, 2, 8, 12, 7, 7, 123);
To format, we have used the String.Format() method and displayed date in different formats.
String.Format("{0:y yy yyy yyyy}", d) String.Format("{0:M MM MMM MMMM}", d) String.Format("{0:d dd ddd dddd}", d
- Related Questions & Answers
- String format for Double in C#
- How to convert string to 24-hour datetime format in MySQL?
- What is the correct DateTime format for a MySQL Database?
- Add10 minutes to MySQL datetime format?
- Insert current date in datetime format MySQL?
- How to convert C# DateTime to “YYYYMMDDHHMMSS” format?
- Input type DateTime Value format with HTML
- How do I re-format datetime in MySQL?
- Adding a day to a DATETIME format value in MySQL?
- C# Nullable Datetime
- How to convert MySQL DATETIME value to JSON format in JavaScript?
- How do you display JavaScript datetime in 12hour AM/PM format?
- Convert DateTime Value into String in MySQL?
- Format String Vulnerability and Prevention with Example in C
- Compare DATE string with string from MySQL DATETIME field?
Advertisements