Hi everyone

I'm new here, and is so often the case with forums, I discovered daniweb whilst googling for a solution!

I'm new to C#, and although I've read loads of books am finding that the best way of learning is to just get stuck in!

I've set myself the task of writing a fairly simple calculator to convert to and from unix time. I've managed the first part ok, and have a working app that converts to unix correctly. However I have come unstuck on the second part :(

I have a textbox input which I convert to integer and validate:

    private void button2_Click(object sender, EventArgs e)

        int anInteger;
        anInteger = Convert.ToInt32(textBox1.Text);
        int i = 0;
            i = int.Parse(textBox1.Text);
        catch (Exception)
            MessageBox.Show("Please put only numbers");

however, I have now come to a grinding halt! The above compiles and works fine, but I've been messing for hours and can only manage to get errors beyond this point.

I'm sure I'll kick myself once I know the answer; basically I now need to convert my integer into dd/MM/yyyy HH:mm:ss format and display in textBox3.

Any help greatly appreciated, thank you


Thanks for that Antenka

I have actually read that loads of times, but for some reason I'm not 'getting' it.....I'll get there eventually.


Well, there're plenty of examples there to play about and understand :)

I don't quite see your problem. If you know the Unix epoch starts at Januari 1, 1970 and a day has 86400 s, it should be easy to calculate what you want. Keep in mind : there are leap seconds! (The year 2038 problem is still a bit away!)

What value of time does the integer represent ?
Seconds, miliseconds ?

You should be able to create a DateTime for the epoch, then add to this the integer in the integer time value as AddSeconds, or AddTicks, etc. to get the value, then as far as displaying it in your
dd/MM/yyyy format is just a formating statement.

// Jerry