如何转换日期格式。 [英] How to convert date format.

查看:114
本文介绍了如何转换日期格式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从txt文件导入数据(07092018)并在sql server中导入,现在我想使用asp.net C将日期格式转换为(07-09-2018)格式#



我尝试了什么:



寻找解决方案,我没有尝试,但搜索了很多没有解决方案找到

解决方案

将其转换为DateTime:

  string  input =   07092018; 
DateTime dt;
if (!DateTime.TryParseExact(input, ddMMyyyy,CultureInfo.InvariantCulture,DateTimeStyles.None, out dt))
{
// 报告数据问题......
return ;
}

然后,您可以按照您选择的任何方式对其进行格式化,或根据需要对其进行操作:

 Console.WriteLine (dt.ToString(  dd-MM-yyyy)); 
Console.WriteLine(dt.ToString( ddd,dd-MMM-yy) );


I am import data(07092018) from txt file and importing in sql server,Now i want to convert date format into (07-09-2018) format using asp.net C#

What I have tried:

Looking for solution and i didn't try yet but searched a lot no solution is found

解决方案

Convert it to a DateTime:

string input = "07092018";
DateTime dt;
if (!DateTime.TryParseExact(input, "ddMMyyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
    {
    // report problem with data...
    return;
    }

You can then format it for presentation in any way you chose, or manipulate it as required:

Console.WriteLine(dt.ToString("dd-MM-yyyy"));
Console.WriteLine(dt.ToString("ddd, dd-MMM-yy"));


这篇关于如何转换日期格式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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