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)
{
unsigned short year, month, day, hour, min, sec, msec;
DateTimePicker1->Date.DecodeDate(&year, &month, &day);
DateTimePicker1->Date.DecodeTime(&hour, &min, &sec, &msec);
TDateTime dt(year, month, 1, hour, min, sec, msec);
DateTimePicker1->Date = dt;
}
[解决办法]
void __fastcall TForm1::Button1Click(TObject *Sender){ DateTimePicker1->Date=StrToDate(Date().FormatString("yyyy-mm-")+"01");}//---------------------------------------