日期时间转换为字符串格式(QUOT; YYYYMMDD") [英] Convert DateTime to string format("yyyyMMdd")

查看:117
本文介绍了日期时间转换为字符串格式(QUOT; YYYYMMDD")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,转换日期时间它是字符串格式,但我不能将其转换为YYYYMMDD格式。

我的code是:

 字符串TPOC = refSubClaim.BenefitsFolder.BenefitFolderIdNumber.ToString();
字符串[] = tpocinfo Regex.Split(TPOC,);的for(int i = 0; I< tpocinfo.Length;我++)
{
    开关(ⅰ)
    {
        情况下0:
        {
            串[] tpoc2 = Regex.Split(tpocinfo [0],,);
            claimantAuxillaryRecord.TPOCDate2 = tpoc2 [0]的ToString();
            claimantAuxillaryRecord.TPOCAmount2 = Convert.ToDecimal(tpoc2 [1]);
            claimantAuxillaryRecord.FundingDelayedBeyondTPOCStartDate2 = tpoc2 [2]的ToString();
        }
        打破;


解决方案

如果您有与格式DDMMYYYY字符串的日期,并希望将其转换为年月日,你可以这样做:

  DateTime的DT = DateTime.ParseExact(dateString,DDMMYYYY
                                  CultureInfo.InvariantCulture);
dt.ToString(年月日);

I am having a problem converting a datetime which is in string format but I am not able to convert it to yyyyMMdd format.

my code is:

string tpoc = refSubClaim.BenefitsFolder.BenefitFolderIdNumber.ToString();
string[] tpocinfo = Regex.Split(tpoc,";");

for (int i = 0; i < tpocinfo.Length; i++)
{
    switch (i)
    {
        case 0:
        {
            string[] tpoc2 = Regex.Split(tpocinfo[0], ",");
            claimantAuxillaryRecord.TPOCDate2 = tpoc2[0].ToString();
            claimantAuxillaryRecord.TPOCAmount2 = Convert.ToDecimal(tpoc2[1]);
            claimantAuxillaryRecord.FundingDelayedBeyondTPOCStartDate2 = tpoc2[2].ToString();
        }
        break;

解决方案

if you have a date in a string with the format "ddMMyyyy" and want to convert it to "yyyyMMdd" you could do like this:

DateTime dt = DateTime.ParseExact(dateString, "ddMMyyyy", 
                                  CultureInfo.InvariantCulture);
dt.ToString("yyyyMMdd");

这篇关于日期时间转换为字符串格式(QUOT; YYYYMMDD&QUOT;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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