每次点击都会添加一天 [英] Adding one day with each click
本文介绍了每次点击都会添加一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我里面有一个TextBox日期dd / MM / yyyy格式
点击时我有一个按钮我想在文本框中找到一天添加一天。
示例TextBox:15/09/2013当我点击我希望文本框文本为16/09/2013
I使用下面的代码,但它在服务器上发布时开始添加月份:
I have a TextBox inside it a date dd/MM/yyyy format
I have a button when clicked I want to add one day to the date found in the textbox.
Example TextBox: 15/09/2013 When I click I want the textbox text be 16/09/2013
I used this code below but it started adding month when published on server:
date_add.Text = CDate(date_add.Text).AddDays(1).ToString("dd/MM/yyyy")
推荐答案
Private Sub MyButton_Click(sender As Object, e As EventArgs) Handles MyButton.Click
Dim culture As New CultureInfo("fr-FR", false) '' Here I took french culture because I'm sure it represents the DateTime format the way you want, i.e. dd/MM/yyyy
Dim myDate As DateTime
myDate = DateTime.Parse(date_add.Text, culture)
date_add.Text = myDate.AddDays(1).ToString("dd/MM/yyyy")
End Sub
希望这有帮助
Hope this helps
您可以使用它来减去日期,并将现有数据添加到您的文本框中。一旦你使用这些方法你就可以得到这些值,你可以打印它们,或者你可以设置一个带有新值的文本框。
You can use this to subtract and add days to the existing data may be in your in a text box. Once you use these methods you get the values and u can print them or you can set teh text box with a fresh value.
using System;
class Program
{
static void Main()
{
Console.WriteLine("Today: {0}", DateTime.Today);
DateTime y = GetYesterday();
DateTime z = GetTomorrow();
Console.WriteLine(y,z);
}
/// <summary>
/// Gets the previous day to the current day.
/// </summary>
static DateTime GetTomorrow()
{
// Add 1 to now
return DateTime.Today.AddDays(1);
}
static DateTime GetYesterday()
{
// Add -1 to now
return DateTime.Today.AddDays(-1);
}
}
这篇关于每次点击都会添加一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文