如何从文本框中分隔月份和年份 [英] How to separate month and year from textbox
本文介绍了如何从文本框中分隔月份和年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
来自日期选择器我在文本框上获得价值,作为月份..
我想把它分开存放在一个变量中..
pelase建议
2015年3月
2016年4月
这些是我的文本框上的值..我想要分月份和年份
Hi ,
from date picker i am getting value on textbox ,, as month year ..
I want to separate that and store in onevariable ..
pelase suggest
March 2015
April 2016
these are the values are on my textbox .. i want to separte month and year
推荐答案
string dateText = "March 2015";
DateTime dt;
if (DateTime.TryParseExact(dateText, "MMMM yyyy", System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dt))
{
// get the month
string month = dt.ToString("MMMM");
// get the year as a string
string yearText = dt.ToString("yyyy");
// or get it as an int
int year = dt.Year;
}
DateTimePicker为您提供属性值所选日期为DateTime。
您只有分离此返回值(DateTimePicker1.Value.Month或DateTimePicker1.Value.Year)
The DateTimePicker delivers you on the Property "Value" the selected Date as DateTime.
You only have to seperate from this Return-Value (DateTimePicker1.Value.Month or DateTimePicker1.Value.Year)
string s = txtReviewStartDate.Text.Trim();
string[] words = s.Split(' ');
int month = DateTime.ParseExact(words[0].ToString(), "MMMM", System.Globalization.CultureInfo.InvariantCulture).Month;
hdnFromMonth.Value = month.ToString();
hdnFromYear.Value = words[1].ToString();
我试过这样,感谢eveyone建议这个问题。我用更好的方式解决了我的问题
I tried like this , thanks eveyone for suggesting for this question . I solved my query with better way
这篇关于如何从文本框中分隔月份和年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文