从tdatetime提取月份 [英] extract month from tdatetime

查看:103
本文介绍了从tdatetime提取月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我想从日期时间(当前月份)中提取月份.我使用

Hello,
I want to extract the month from a datetime (the present month). I use the

DecodeDate(date,year,month,day);
edit1.Text := datetimetostr(month);


但是它给了我2/1/1900的完整日期,我使用Delphi 7很奇怪.有帮助吗?

谢谢
Kyriakos


but it gives me as a result the full date of 2/1/1900, it is weird I am using Delphi 7. Any help?

Thank you
Kyriakos

推荐答案

基于此信息 [ ^ ]它按照您的要求去做.尝试仅打印月份值.
Based on this information[^] it''s doing what you asked. Try printing just the month value.


您快到了!您已经检索了月份,但是显示结果有问题.

一个正确的例子是
You''re almost there! You''ve already retrieve the month, but there is something wrong with showing the result.

A correct example would be
procedure ShowMonth;
var
  Day, Year, Month: Word;
  Today: TDateTime;
begin
  Today:= Now;
  DecodeDate(Today, Year, Month, Day);
  ShowMessage(IntToStr(Month));//Month here is 1, 2, ..., 12
end;



问题出在对DateTimeToStr的调用上,该调用采用的TDateTime只是Double的一种,这意味着自1899年12月30日以来的天数.

因此,对DateTimeToStr的调用只会给您大约1900年的某天,具体取决于您所获得的Month的值.



The problem is from the call to DateTimeToStr which takes a TDateTime which is just a type of Double which means number of days since Dec 30 1899.

So, the call to DateTimeToStr will just give you some day around 1900, depending on the value of Month you have got.


这篇关于从tdatetime提取月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆