Write specified date as yyyy-MM-dd HH:mm:ss - CSharp System

CSharp examples for System:DateTime Format

Description

Write specified date as yyyy-MM-dd HH:mm:ss

Demo Code


using System.Xml.Serialization;
using System.Collections;
using System.Globalization;
using System.Collections.Specialized;
using System.Text;
using System.Collections.Generic;
using System;// w w  w .  ja  v  a 2 s  . co m

public class Main{
        /// <summary>
		/// Write specified date as yyyy-MM-dd HH:mm:ss
		/// </summary>
		/// <param name="dateTime"></param>
		/// <returns></returns>
		public static string DateTimeToStringSortable(DateTime dateTime)
		{
			return dateTime.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss");
		}
}

Related Tutorials