forum

Home / DeveloperSection / Forums / Date & time not displaying correctly

Date & time not displaying correctly

Anonymous User245518-Dec-2013

I am creating my first win form application, written in C#. I have added a little bit of code to display the current date and time on the first tab page as below:                                                                                                                           

    private void Form1_Load(object sender, EventArgs e)

    {

        // connect to database

        c = new Connection();

        connect.ConnectionString = c.getConnection();

        //deals with date and time

        Timer tmr = new Timer();

        tmr.Interval = 1000;//ticks every 1 second

        tmr.Tick += new EventHandler(tmr_Tick);

        tmr.Start();

    }

    private void tmr_Tick(object sender, EventArgs e)

    {

        labeltime.Text = DateTime.Now.ToString(" Todays Date: dd/MM/yyyy\n\n Current     Time: HH:mm:ss");

    }

The output in not correct however. The date and time are correct and ticking away nicely but where I want it to display "Todays Date:" it is messy like " To15a1342 (42 being the seconds from the time, ticking away) and the "Current Time" reads CuRRenP Ti50e:

Does it matter that I am in the UK? Would this require me to use different code or something?


Updated on 18-Dec-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By