Change datetime format from one to another programmatically

旧街凉风 提交于 2019-12-10 11:47:39

问题


In my program, I need to change the input datetime information from Turkish (d.M.yyyy) language to English (M/dd/yyyy).

When client edits datetime information in Turkish datetime format(For Example: 24.9.2015), i need to convert this information in English datetime format(Like; 9/24/2015).

I'm trying to parse the input, but not convert the correct format that i need, code block as in the following.

DateTime.TryParseExact(InputDate,"d.M.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out result))

I need the output named "result" in English U.S datetime format. I also tried to change the code as CultureInfo(en-US) but it doesn't work.

Any ideas?


回答1:


In what language are you trying to achieve this?

Assuming it is c#, DateTime does not have a specific format until you try to convert it into a string and you can convert it to US version by specifying the correct format when calling ToString()

string americanFormat = myDate.ToString("MM/dd/yyyy");


来源:https://stackoverflow.com/questions/32444120/change-datetime-format-from-one-to-another-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!