DateTime.Now.ToString("MM/DD/YYYY")包含错误的月份 [英] DateTime.Now.ToString("MM/DD/YYYY") contains incorrect month

查看:190
本文介绍了DateTime.Now.ToString("MM/DD/YYYY")包含错误的月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我一直在将DateTime.Now.ToString("MM/DD/YYYY")添加到列表(以及大量其他数据),然后将这些列表写入Excel工作簿中的各个行.

So I have been adding a DateTime.Now.ToString("MM/DD/YYYY") to a List (along with a bunch of other data) and the later writing these lists to individual rows in an Excel workbook.

除了月份之外,这一切都很好(我经常这样做).我尝试将其导出三次,每次获得不同的月份时都进行导出; 第一次56/26-17, 第二个2/26/2017, 和第三次14/26/2017 ....

This all works great (it's something I do regularly), except, the month. I have tried exporting it three times and each time I get a different month; the first time 56/26-17, the second 2/26/2017, and the third 14/26/2017....

推荐答案

请改用此:

DateTime.Now.ToString("MM/dd/yyyy")

"MM"一个月. "dd"天.年份为"yyyy".

"MM" for month. "dd" for days. "yyyy" for year.

"MM/DD/YYYY"格式错误:

"MM/DD/YYYY" is wrong format:

Console.WriteLine(DateTime.Now.ToString("MM/DD/YYYY")) // prints "06/DD/YYYY"

这篇关于DateTime.Now.ToString("MM/DD/YYYY")包含错误的月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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