I want to get the clock from datetime. So if it is 1pm, it will be only 1, if it is 10pm, it will be 10. Thus, no leading zero will be placed in hours 1-9
So I tried to do it
DateTime test= DateTime.Now; Console.WriteLine(test.ToString("h"));
I get it
System.FormatException was not handled
Message = The input string was not in the correct format. Source = mscorlib
Stack trace: a System.DateTimeFormat.GetRealFormat (String format, DateTimeFormatInfo dtfi) in System.DateTimeFormat.ExpandPredefinedFormat (String format, DateTime & DATETIME, DateTimeFormatInfo & dtfi, TimeSpan & displacement) in System.DateTimeFormat.Format (DateTime dateTime, String format , DateTimeFormatInfo dtfi, TimeSpan offset) in System.DateTimeFormat.Format (DateTime dateTime, String format, DateTimeFormatInfo dtfi) in System.DateTime.ToString (String format) in ConsoleApplication1.Program.Main (String [] args) in C: \ Users \ chobo2 \ Documents \ Visual Studio 2010 \ Projects \ ConsoleApplication1 \ ConsoleApplication1 \ Program.cs: lines 21 in System.AppDomain._nExecuteAssembly (RuntimeAssembly assembly, String [] args) in System.AppDomain.ExecuteAssembly (String assembly, proof StringSecurity [] args) at Microsoft. VisualStudio.HostingProcess.HostProc.RunUsersAssembly () in System.Threading.ThreadHelper.ThreadStart_Context (Object state) in System.Threading.ExecutionContext.Run (ExecutionContext executeContext, ContextCallback callback, object state, boolean value ignoreSyncThreadtext .Run (ExecutionContext executeContext, ContextCallback callback, object state) in System.Threading.ThreadHelper.ThreadStart () InnerException:
c # formatting
chobo2
source share