删除前导零的形式月份C# [英] Remove leading zero form month C#

查看:1021
本文介绍了删除前导零的形式月份C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法去除,我发现这个miscrosoft网站上的日期前导零。

I'm having trouble to remove the leading zero from a date I found this on the miscrosoft website.

DateTime date1 = new DateTime(2008, 8, 18);
Console.WriteLine(date1.ToString("(M) MMM, MMMM", 
                  CultureInfo.CreateSpecificCulture("en-US")));
// Displays (8) Aug, August



完全不在这里工作了。

Totally doesn't work here.

这是我的代码:

string date = '2013-04-01'
DateTime billrunDate = Convert.ToDateTime(date);
string test = billrunDate.ToString("M");



现在测试 04月01日

我只需要它是 4 在字符串或INT IDC
谢谢!

I just need it to be 4 in a string or int idc Thanks!

编辑,如果我做的:

billrunDate.ToString("(M)");



我得到(4),但我不需要()

编辑2:
嗯,这工作

EDIT 2: Well this works

string test = billrunDate.ToString(" M ");
string testTwo = test.Trim();



非常非常难看。

Very very ugly

推荐答案

它解释 M 作为的标准日期和时间格式以月日模式

It's interpreting M as a standard date and time format for "month day pattern".

要解释一个字符图案作为的自定义日期和时间格式,只需用前缀是:

To interpret a single character pattern as a custom date and time pattern, just prefix it with %:

string test = billrunDate.ToString("%M");

这篇关于删除前导零的形式月份C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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