Where is the system locale/culture set for .Net

后端 未结 7 1522
时光取名叫无心
时光取名叫无心 2020-12-09 20:49

I have a problem with a c# assembly (.net 2.0 written using Visual studio 2005) that is installed on a UK server and should use UK regional settings.

What my code do

7条回答
  •  生来不讨喜
    2020-12-09 21:30

    You do not have to change the CurrentCulture to do the transformation. If you are certain that the date is in the form of "dd/MM/yyyy" you could use

    DateTime dtTemp = DateTime.ParseExact(dateString, "dd/MM/yyyy", null) // in order not to have to specify a FormatProvider
    

    and then use

    dtTemp.ToString("yyyy-MM-dd")
    

    This way you will not have a problem no matter what the CurrentCulture is. However, if you are not certain that the Date is of the form "dd/MM/yyyy" rather it is based on the CurrentCulture short date format, then you should use

    DateTime dtTemp = DateTime(dateString, CurrentCulture.DateTimeFormat.ShortDatePattern, CurrentCulture.DateTimeFormat);
    

提交回复
热议问题