Last active
August 29, 2015 14:01
-
-
Save nramsbottom/2296fffdf49fcb824fe4 to your computer and use it in GitHub Desktop.
Simple command line date and time formatter for use in batch scripts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| namespace dttm | |
| { | |
| class Program | |
| { | |
| static int Main(string[] args) | |
| { | |
| // no arguments. write current local date and time in iso-8601 format | |
| if (args.Length == 0) | |
| { | |
| Console.WriteLine("Usage: dttm <format> <switches>"); | |
| Console.WriteLine("Switches:"); | |
| Console.WriteLine(" /utc UTC output"); | |
| Console.WriteLine(" /lowercase Output is in lowercase"); | |
| return 1; | |
| } | |
| var isUtc = args.Contains("/utc", StringComparer.InvariantCultureIgnoreCase); | |
| var isLowerCase = args.Contains("/lowercase", StringComparer.InvariantCultureIgnoreCase); | |
| var format = args[0]; | |
| var date = isUtc ? DateTime.UtcNow : DateTime.Now; | |
| var output = date.ToString(format); | |
| if (isLowerCase) | |
| Console.WriteLine(output.ToLower()); | |
| else | |
| Console.WriteLine(output); | |
| return 0; | |
| } // Main | |
| } // class | |
| } // namespace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment