What I want is when user input text in textbox in date format, text change to string. for example when user enters 9/25/2012 I have to store it as 20120925. Help would be appreciated
我想要的是当用户在日期格式的文本框中输入文本时,文本更改为字符串。例如,当用户输入9/25/2012时,我必须将其存储为20120925.帮助将不胜感激
6 个解决方案
#1
6
string converted = DateTime.ParseExact(strInput, "MM/dd/yyyy", CultureInfo.InvariantCulture)
.ToString("yyyyMMdd");
#2
1
string str = blackOutFromDate.ToString("yyyyMMdd");
#3
1
fileName
contains that date string. So, I split the fileName
using an empty string as a delimiter, to get the expectedDate
.
fileName包含该日期字符串。因此,我使用空字符串作为分隔符拆分fileName,以获取expectedDate。
I then split the expectedDate
using "-" as delimiter and convert it to datetime
.
然后我使用“ - ”作为分隔符拆分expectedDate并将其转换为datetime。
string[] splitFileName = fileName.Split(' ');
string expectedDate = (splitFileName[1]);
string[] dateparts = expectedDate.Split('-');
expextedDate = dateparts[1] + "-" + dateparts[0] + "-" + dateparts[2];
DateTime CallDate = Convert.ToDateTime(expextedDate);
#4
0
Use System.DateTime
class
使用System.DateTime类
var date = Convert.ToDateTime(textBox1.Text);
textBox1.Text = date.Year + "" + date.Month + date.Day;
#5
0
Try this
尝试这个
var date = DateTime.Parse("9/25/2012");
var modified = string.format("{0}{1}{2}", date.Year, date.Month, date.Day);
#6
0
You can try this, it worked for me.
你可以尝试这个,它对我有用。
DateTime dt = Convert.ToDateTime(txtFrom.Text);
string date = Convert.ToDateTime(dt).ToString("yyyyMMdd");
#1
6
string converted = DateTime.ParseExact(strInput, "MM/dd/yyyy", CultureInfo.InvariantCulture)
.ToString("yyyyMMdd");
#2
1
string str = blackOutFromDate.ToString("yyyyMMdd");
#3
1
fileName
contains that date string. So, I split the fileName
using an empty string as a delimiter, to get the expectedDate
.
fileName包含该日期字符串。因此,我使用空字符串作为分隔符拆分fileName,以获取expectedDate。
I then split the expectedDate
using "-" as delimiter and convert it to datetime
.
然后我使用“ - ”作为分隔符拆分expectedDate并将其转换为datetime。
string[] splitFileName = fileName.Split(' ');
string expectedDate = (splitFileName[1]);
string[] dateparts = expectedDate.Split('-');
expextedDate = dateparts[1] + "-" + dateparts[0] + "-" + dateparts[2];
DateTime CallDate = Convert.ToDateTime(expextedDate);
#4
0
Use System.DateTime
class
使用System.DateTime类
var date = Convert.ToDateTime(textBox1.Text);
textBox1.Text = date.Year + "" + date.Month + date.Day;
#5
0
Try this
尝试这个
var date = DateTime.Parse("9/25/2012");
var modified = string.format("{0}{1}{2}", date.Year, date.Month, date.Day);
#6
0
You can try this, it worked for me.
你可以尝试这个,它对我有用。
DateTime dt = Convert.ToDateTime(txtFrom.Text);
string date = Convert.ToDateTime(dt).ToString("yyyyMMdd");