Get Time Zones list in c# [duplicate] - c#

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do I enumerate all time zones in .NET?
How can I get the list of time zones with c#?
I want a list like the one windows has.

GetSystemTimeZones().
ReadOnlyCollection<TimeZoneInfo> tz;
tz= TimeZoneInfo.GetSystemTimeZones();
Keep in mind that this returns a ReadOnlyCollection(T)
You can also learn how to populate a list with those timezones here.

You can use TimeZoneInfo.GetSystemTimeZones().

TimeZoneInfo.GetSystemTimeZones()

Related

C# - DateTime.Now.TimeOfDay is different on my other comptuter by 2 seconds, how do I get accurate time? [duplicate]

This question already has answers here:
How to Query an NTP Server using C#?
(6 answers)
Closed 3 years ago.
I need to get the same time on all Instances of my program. How do I do that. DateTime.Now is not accurate(is different on different hardware) enough, I need to get the Time down to 100 ms difference-precision.
You don't want it read locally from each computer, as you don't know that each PC's clock is perfectly in sync (and you can see that they aren't).
So you have two options:
Write something on each computer to maintain precise time.
Get a web based time and all of your computers will be reading the same data. Here is an example from SO: How to get DateTime from the internet?

Query a list and select top 10 values [duplicate]

This question already has answers here:
How to get first N elements of a list in C#?
(7 answers)
Closed 4 years ago.
I have a list of objects in which each object has a property called "Frequency" and I want to be able to pick the top 10 objects that have the highest frequencies.
I saw some solutions that are kind of similar to what I am looking to solve using LINQ so any help is appreciated.
You can order the list by descending Frequency and then take the first 10 like this:
var top10 = objectList.OrderByDescending(o => o.Frequency).Take(10);

How to get only Folder Creation Date in C# [duplicate]

This question already has answers here:
Getting Date or Time only from a DateTime Object
(7 answers)
Closed 8 years ago.
I know that, Example: DateTime fileCreatedDate = File.GetCreationTime(#"C:\Example\MyTest.txt");will return the date and time of a folder creation but how do I only get the "Date"Example "2014-12-01" or "Decemeber 12,2014" of the folder creation excluding the time?
You can use the DateTime.Date property for that, i.e. fileCreatedDate.Date.

Convert String to Date only in C# [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Convert String to Date in .NET
I new here, I'm stuck with this problem when a have an array of strings with values of "120612" and "200612".
I need to convert the strings to a date format like this, "Tues 12 June, 2012". How will I do that?
Thanks in advance.
DateTime.ParseExact is probably what you're looking for:
DateTime.ParseExact("200612", "ddMMyy", System.Globalization.CultureInfo.CurrentCulture)

Update system time and date from internet [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to Query an NTP Server from C#
I try send email with my program but if time and date not set, sending is be fail.
How to update system time and date from internet in C#?
The answers to this question show you how to retrieve the time from a time server.
Are you sure you want to update the system time? Maybe it is sufficient to use the retrieved time in the email.

Categories