hi,
In some project i need to display the current time as shown in taskbar. I have tried the code below
CultureInfo p = CultureInfo.CurrentCulture;
DateTime dt = DateTime.Now;
string t = dt.ToString("T", p);
Console.Write(t);
My current time is 3:32 (According to my system's taskbar) and this code displays as 3:32:45. it should show exactly 3:32
My current regional setting is (English United States). I have customized the time format to H:mm:ss by clicking customise button in regional settings from control panel.
If i change the customized setting then this change is reflected in task bar and this must reflect in the code above, Now i customize the setting to hh:mm:ss tt, task bar displays 03:40 AM and code shows 03:40:28 AM. seconds should not be displayed.

From what I can see the code is correct and the task bar is showing the wrong time format.
I tried using HH:ss as the time format and the task bar only showed the hours.:confused:
It seems the task bar always suppresses the seconds; probably to reduce number of updates needed to the task bar.
To exactly match what is in the task bar you will have to do something similar.
Try inspecting the DateTimeFormat.LongTimePattern and remove the seconds portion. Then use the new pattern to format the time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.