Datetimepicker 获取当前月份第一天
使用Datetimepicker控件
获取当前月份的第 一天,显示在界面上。如:2009-9-1
我用Date();可以获取当前日期,但不知道怎么转换到第一天。
[解决办法]
//---------------------------------------
#include <vcl.h>
#include <DateUtils.hpp> //一定要加上头文件
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime dtFirstDay;
dtFirstDay = Now().CurrentDate() - DayOfTheMonth(Now().CurrentDate()) + 1;
DateTimePicker1->Date = dtFirstDay;
}
//---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
DateTimePicker1->Date=StrToDate(Date().FormatString("yyyy-mm-")+"01");
}
//---------------------------------------