以编程方式将日期时间格式从一种更改为另一种 [英] Change datetime format from one to another programmatically

查看:123
本文介绍了以编程方式将日期时间格式从一种更改为另一种的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,我需要将输入日期时间信息从土耳其语(d.M.yyyy)语言更改为英语(M/dd/yyyy).

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

当客户以土耳其语日期时间格式(例如24.9.2015)编辑日期时间信息时,我需要将此信息转换为英语日期时间格式(例如2015年9月24日).

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))

我需要美国英语日期时间格式的名为结果"的输出.我还尝试将代码更改为CultureInfo(en-US),但无法正常工作.

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.

有什么想法吗?

推荐答案

您要尝试使用哪种语言来实现?

In what language are you trying to achieve this?

假设它是c#,在尝试将其转换为字符串之前,DateTime不会具有特定格式,并且可以在调用ToString()时通过指定正确的格式将其转换为美国版本

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");

这篇关于以编程方式将日期时间格式从一种更改为另一种的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆