Skip to content

Instantly share code, notes, and snippets.

@nramsbottom
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save nramsbottom/2296fffdf49fcb824fe4 to your computer and use it in GitHub Desktop.

Select an option

Save nramsbottom/2296fffdf49fcb824fe4 to your computer and use it in GitHub Desktop.
Simple command line date and time formatter for use in batch scripts.
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