将日期时间转换为SHAMSI(波斯语,伊朗) [英] convert datetime to SHAMSI(Persian,Iran)

查看:117
本文介绍了将日期时间转换为SHAMSI(波斯语,伊朗)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将系统DateTime转换为Shamsi datetime?

How can I convert system DateTime to Shamsi datetime?

推荐答案

请参阅类似问题的答案 ^ ].
See the answers to a this similar question Convert time help needed[^].
SAKryukov写道:
SAKryukov wrote:

如果要在Shamsi时区(伊朗标准时间)中选择当前时间,可以使用TimeZoneInfo类 [

If you want the current time in the time zone of Shamsi (Iran Standard Time) you can use the the TimeZoneInfo Class[^] and one of its conversion functions.

For example:

TimeZoneInfo::ConvertTimeBySystemTimeZoneId( DateTime.Now, "Iran Standard Time" );



如果要以Shamsi中使用的格式显示时间,则需要将DateTime转换为字符串.
为此,您可以使用System.DateTime.ToString(IFormatProvider)考虑伊朗文化.您需要使用ICultireInfo的实例,因为它实现了IFormatProvider.请在此处查看代码示例:
http://msdn.microsoft.com/en-us/library/ht77y576 .aspx [^ ] .

当然,请使用适当的区域性代码代替"ja-JP".



If you want to show the time in the format used in Shamsi you will need to convert the DateTime to a string.
For this you use System.DateTime.ToString(IFormatProvider) to take into account Iranian culture. You need to use the instance of ICultireInfo as it implements IFormatProvider. Please see the code sample here: http://msdn.microsoft.com/en-us/library/ht77y576.aspx[^].

Of course, put appropriate culture code instead of "ja-JP".


您好,


使用System.Globalization.PersianCalendar

http://msdn.microsoft.com/en-us/library/system.globalization. persiancalendar.aspx [ ^ ]


例如,您有一个系统DateTime(DateInSystemDateTime)

Hello,


Use System.Globalization.PersianCalendar

http://msdn.microsoft.com/en-us/library/system.globalization.persiancalendar.aspx[^]


For example you have a system DateTime (DateInSystemDateTime)

System.Globalization.PersianCalendar persianCalandar = 
                                    new System.Globalization.PersianCalendar();

int year = persianCalandar.GetYear(DateInSystemDateTime);
int month = persianCalandar.GetMonth(DateInSystemDateTime);
int day = persianCalandar.GetDayOfMonth(DateInSystemDateTime);


很抱歉,如果我的回答是多余的,但我没有不喜欢答案的某些错误陈述(请参阅我对安德烈·克拉克的答案的评论,所以让我直接参考我最近的答案:
转换所需的时间帮助 [
Sorry if my answer is redundant, but I don''t like certain misrepresentation of the answer (please see my comment to the answer by André Kraak, so let me reference my recent answer, directly:
Convert time help needed[^].

From your standpoint, you might be more interested in having the original answer, because 1) I updated it two times since it was referenced, 2) it is the most detailed and correctly summarize the topic and correctly credit another answer.

Good luck,
—SA


这篇关于将日期时间转换为SHAMSI(波斯语,伊朗)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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