Click here to Skip to main content
15,892,298 members
Articles / Programming Languages / C#

Building a UNIX Time to Date Custom Control in C#

Rate me:
Please Sign up or sign in to vote.
3.67/5 (3 votes)
6 Jun 2008CPOL5 min read 29.5K   108   9  
This article addresses the construction of a custom control that will convert UNIX time into useful and readable dates for display in a WinForms application.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ControlTest
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // use negative numbers to express dates
            // prior to 1/1/1970

            // load with unix time
            utConverter1.Text = "-885772800";  // a date prior to 1/1/1970
            utConverter2.Text = "849312000";
            utConverter3.Text = "999648000";
            utConverter4.Text = "4000000000";

            // load with normal dates
            utConverter5.Text = "7/19/1960";
            utConverter6.Text = "5/16/1933";
            utConverter7.Text = "7/4/2008";
            utConverter8.Text = "6/18/3100";

            // refresh all of the controls
            // to update the display
            utConverter1.Refresh();
            utConverter2.Refresh();
            utConverter3.Refresh();
            utConverter4.Refresh();
            utConverter5.Refresh();
            utConverter6.Refresh();
            utConverter7.Refresh();
            utConverter8.Refresh();

            // move selection off custom controls
            button1.Select();

        }
    }
}

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)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions