System.DateTimie

A

AA2e72E

I am struggling a little with these 2 problems:

1. How can I convert an integer, representing x days from 01/01/0001 (the
minimum value for DateTime, in dd/MM/yyyy) to dd/MM/yyyy?
2. Is there any functionality for converting a date from one locale to
another?

Thanks for your help.
 
A

Alberto Poblacion

AA2e72E said:
1. How can I convert an integer, representing x days from 01/01/0001 (the
minimum value for DateTime, in dd/MM/yyyy) to dd/MM/yyyy?

string result = (new DateTime(1,1,1)).AddDays(x).ToString("dd/MM/yyyy");
 
M

Morten Wennevik [C# MVP]

Hi,

1)
To creat a DateTime object given as x days since January 1st 0001 use

DateTime dt = DateTime.MinValue.AddDays(numerOfDays);

2)
A date is stored internally independent of any culture. If you want to
output the date in a specific culture format, you can use that culture's
DateTimeFormat

DateTime.Now.ToString(System.Globalization.CultureInfo.GetCultureInfo("nb-NO");

The above will print dates with Norwegian formatting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top