Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Encrypting Editor Notepad Replacement

, 28 Jul 2014 CPOL
A C# .NET 3.5 (Win7) Windows Forms Application with source code
CryptPad-SourceOnly.zip
CryptPad
CryptPad (read-only).lnk
CryptPad.suo
CryptPad
CryptPad.csproj.user
CryptPad.ico
CryptPad.png
Properties
Settings.settings
hack.safe
Script.CryptPad
SendTo.lnk
Settings.lnk
CryptPad.png
CryptPad.zip
CryptPad (read-only).lnk
CryptPad.suo
CryptPad.csproj.user
CryptPad.ico
CryptPad.png
Settings.settings
hack.safe
Script.CryptPad
SendTo.lnk
Settings.lnk
CryptPad.exe
CryptPad.png
using System;
using System.Globalization;

namespace DateTimeISO_Class
{
	/// <summary> ISO 8601 generic datetime functions example: 2001-06-01 12:13:13.222
	/// designed for standard Windows 7 .Net 3.5 where timespan.tostring has no format
	/// </summary> 
	static class DateTimeISO
	{
		static string[] formats = {
			"yyyy-MM-dd HH:mm:ss.fff", 
			"yyyy-MM-dd HH:mm:ss", 
			"yyyy-MM-dd HH:mm", 
            "yyyy-MM-dd", 
            "HH:mm:ss.fff",
			"HH:mm:ss",
			"HH:mm"};

		// Difference from a provided reference standard
		static TimeSpan local = new TimeSpan (0);

		/// <summary> Adjust DateTime.Now to reference time value
		/// </summary> 
		public static void Now (DateTime actual)
		{
			local = actual - DateTime.Now;
		}
		/// <summary> Return adjusted DateTime.Now 
		/// </summary> 
		public static DateTime Now ()
		{
			return DateTime.Now + local;
		}
		/// <summary> Return ISO format time string for DateTime.Now 
		/// including hours, minutes, seconds, milliseconds
		/// </summary> 
		public static string strTime ()
		{
			return strTime (Now ());
		}
		/// <summary> Return ISO format time string for DateTime.Now 
		/// including hours, minutes, seconds
		/// </summary> 
		public static string strTimeHMS ()
		{
			return strTimeHMS (Now ());
		}
		/// <summary> Return ISO format time string for DateTime.Now 
		/// including hours, minutes
		/// </summary> 
		public static string strTimeHM ()
		{
			return strTimeHM (Now ());
		}
		/// <summary> Return ISO format date string for DateTime.Now
		/// </summary> 
		public static string strDate ()
		{
			return strDate (Now ());
		}
		/// <summary> Return ISO format datetime string for DateTime.Now
		/// including hours, minutes, seconds, milliseconds
		/// </summary> 
		public static string strDateTime ()
		{
			return strDateTime (Now ());
		}
		/// <summary> Return ISO format datetime string for DateTime.Now
		/// including hours, minutes, seconds
		/// </summary> 
		public static string strDateTimeHMS ()
		{
			return strDateTimeHMS (Now ());
		}
		/// <summary> Return ISO format datetime string for DateTime.Now
		/// including hours, minutes
		/// </summary> 
		public static string strDateTimeHM ()
		{
			return strDateTimeHM (Now ());
		}
		/// <summary> Return ISO format time string for TimeSpan value
		/// including hours, minutes, seconds, milliseconds
		/// </summary> 
		/// <param name="timespan">The TimeSpan value to convert to string</param> 
		public static string strTime (TimeSpan timespan)
		{
			// no TimeSpan format string in standard windows 7 .Net 3.5
			return timespan.Hours.ToString ("00") + ":"
				+ timespan.Minutes.ToString ("00") + "."
				+ timespan.Seconds.ToString ("00") + "."
				+ timespan.Milliseconds.ToString ("00");
		}
		/// <summary> Return ISO format time string for TimeSpan value
		/// including hours, minutes, seconds
		/// </summary> 
		/// <param name="timespan">The TimeSpan value to convert to string</param> 
		public static string strTimeHMS (TimeSpan timespan)
		{
			// no TimeSpan format string in standard windows 7 .Net 3.5
			return timespan.Hours.ToString ("00") + ":" 
				+ timespan.Minutes.ToString ("00")				+ ":" 
				+ timespan.Seconds.ToString ("00");
		}
		/// <summary> Return ISO format time string for TimeSpan value
		/// including hours, minutes
		/// </summary> 
		/// <param name="timespan">The TimeSpan value to convert to string</param> 
		public static string strTimeHM (TimeSpan timespan)
		{
			// no TimeSpan format string in standard windows 7 .Net 3.5
			return timespan.Hours.ToString ("00") + ":"
				+ timespan.Minutes.ToString ("00") 				;
		}
		/// <summary> Return ISO format time string for TimeSpan value
		/// including minutes, seconds
		/// </summary> 
		/// <param name="timespan">The TimeSpan value to convert to string</param> 
		public static string strTimeMS (TimeSpan timespan)
		{
			// no TimeSpan format string in standard windows 7 .Net 3.5
			return timespan.Minutes.ToString ("00")					+ ":" 
				+ timespan.Seconds.ToString ("00");
		}
		/// <summary> Return ISO format datetime string for DateTime value
		/// including hours, minutes, seconds, milliseconds
		/// </summary> 
		/// <param name="datetime">The DateTime value to convert to string</param> 
		public static string strTime (DateTime datetime)
		{
			return datetime.ToString (formats[4]);
		}
		/// <summary> Return ISO format datetime string for DateTime value
		/// including hours, minutes, seconds
		/// </summary> 
		/// <param name="datetime">The DateTime value to convert to string</param> 
		public static string strTimeHMS (DateTime datetime)
		{
			return datetime.ToString (formats[5]);
		}
		/// <summary> Return ISO format datetime string for DateTime value
		/// including hours, minutes
		/// </summary> 
		/// <param name="datetime">The DateTime value to convert to string</param> 
		public static string strTimeHM (DateTime datetime)
		{
			return datetime.ToString (formats[6]);
		}
		/// <summary> Return ISO format datetime string for DateTime value
		/// </summary> 
		/// <param name="datetime">The DateTime value to convert to string</param> 
		public static string strDate (DateTime datetime)
		{
			return datetime.ToString (formats[3]);
		}
		/// <summary> Return ISO format datetime string for DateTime value
		/// including hours, minutes, seconds, milliseconds
		/// </summary> 
		/// <param name="datetime">The DateTime value to convert to string</param> 
		public static string strDateTime (DateTime datetime)
		{
			return datetime.ToString (formats[2]);
		}
		/// <summary> Return ISO format datetime string for DateTime value
		/// including hours, minutes, seconds
		/// </summary> 
		/// <param name="datetime">The DateTime value to convert to string</param> 
		public static string strDateTimeHMS (DateTime datetime)
		{
			return datetime.ToString (formats[1]);
		}
		/// <summary> Return ISO format datetime string for DateTime value
		/// including hours, minutes
		/// </summary> 
		/// <param name="datetime">The DateTime value to convert to string</param> 
		public static string strDateTimeHM (DateTime datetime)
		{
			return datetime.ToString (formats[0]);
		}
		/// <summary> Return DateTime value from ISO format date and/or time string
		/// </summary> 
		/// <param name="str">The string to convert to DateTime value</param> 
		public static DateTime TryParseExact (string str)
		{
			DateTime dateValue;

			DateTime.TryParseExact (str, formats, new CultureInfo ("en-US"),
						   DateTimeStyles.None, out dateValue);
			return dateValue;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Frank T. Clark
Systems Engineer Three Angels Broadcasting Network
United States United States
I am a Software Systems Design Engineer experienced with IEEE standards and the entire IEEE software development life cycle. Concept Exploration, Requirements, Design, Implementation, Test, Installation and Checkout, Operation and Maintenance. I enjoy working with people and solving customer problems.
 
I am currently employed as Information Technology Staff in the religious satellite broadcasting industry.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411023.1 | Last Updated 28 Jul 2014
Article Copyright 2013 by Frank T. Clark
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid