问题描述
我得到了一个日期设置为071712的数组...日期不带斜杠字符,没有破折号.没什么...只是普通071712(来自文本文件).
我需要转换日期,以便可以将其包括在sql服务器插入中.我正在为插入调用存储过程.到目前为止,我已经知道了:
I got an array with a date set as 071712... no / slash characters for the date, no dash. nothing...just plain 071712 (coming from a text file).
I need to conver the date so I can include it on a sql server insert. I''m calling a stored procedure for the insert. So far I got this:
DateTime date = Convert.ToDateTime(fileLines[4]); // This is not working so far.
(日期将用作存储过程的参数)
请共享一些代码.谢谢.
(date will be used as a parm for the stored procedure)
Pls share some code. Thank you.
推荐答案
CultureInfo provider = CultureInfo.InvariantCulture;
DateTime date= DateTime.ParseExact(fileLines[4], "MMddyy", provider);
string date = "071712";
string format = "MMddyy";
DateTime parsedDate = DateTime.ParseExact(date, format, CultureInfo.InvariantCulture);
希望对您有帮助.
不同的DateTime格式为:
d-月份中的数字,不带前导零.
dd-月份中的数字,前导零.
ddd-星期几的缩写名称.
dddd-星期几的全名.
f,ff,fff,ffff,fffff,ffffff,fffffff-秒的分数. F越大,精度越高.
h-12小时制,无前导零.
hh-12小时制,前导零.
H-24小时制,无前导零.
HH-24小时制,前导零.
m-无前导零的分钟.
毫米-以零开头的分钟.
M-数值月,无前导零.
MM-数值前导零的月份.
MMM-月份的缩写.
MMMM-完整的月份名称.
s-无前导零的秒数.
ss-前导零的秒数.
t-AM/PM,但只有第一个字母.
tt-AM/PM(上午/下午)
y-无世纪且前零的年份.
yy-无世纪的年份,前导零.
yyyy-年与世纪.
zz-时区设置为+/-.
Hope it will help you.
Different DateTime Formats are:
d - Numeric day of the month without a leading zero.
dd - Numeric day of the month with a leading zero.
ddd - Abbreviated name of the day of the week.
dddd - Full name of the day of the week.
f,ff,fff,ffff,fffff,ffffff,fffffff - Fraction of a second. The more Fs the higher the precision.
h - 12 Hour clock, no leading zero.
hh - 12 Hour clock with leading zero.
H - 24 Hour clock, no leading zero.
HH - 24 Hour clock with leading zero.
m - Minutes with no leading zero.
mm - Minutes with leading zero.
M - Numeric month with no leading zero.
MM - Numeric month with a leading zero.
MMM - Abbreviated name of month.
MMMM - Full month name.
s - Seconds with no leading zero.
ss - Seconds with leading zero.
t - AM/PM but only the first letter.
tt - AM/PM ( a.m. / p.m.)
y - Year with out century and leading zero.
yy - Year with out century, with leading zero.
yyyy - Year with century.
zz - Time zone off set with +/-.
这篇关于将日期MMDDYY转换为日期以进行数据库插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!