在线等,回答正确,立马给分!-如何取一年中的当前周数

木棉花大榕树 2005-04-14 09:03:40
问:用那个控件或者不用控件也行,取得当前时间的周数,比如说当前是一年中的第2周,则返回数字是2,如何实现,多谢!
...全文
125 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
samchoy 2005-04-15
  • 打赏
  • 举报
回复
Returns the week of the year represented by a TDateTime value.

Unit
DateUtils

Category
date/time routines

extern PACKAGE Word __fastcall WeekOfTheYear(const System::TDateTime AValue);
extern PACKAGE Word __fastcall WeekOfTheYear(const System::TDateTime AValue, Word &AYear);

Description
Call WeekOfTheYear to obtain the week of the year represented by a specified TDateTime value. WeekOfTheYear returns a value between 1 and 53.

AYear returns the year in which the specified week occurs. Note that this may not be the same as the year of AValue. This is because the first week of a year is defined as the first week with four or more days in that year. This means that if the first calendar day of the year is a Friday, Saturday, or Sunday, then for the first three, two, or one days of the calendar year, WeekOfTheYear returns the last week of the previous year. Similarly, if the last calendar day of the year is a Monday, Tuesday, or Wednesday, then for the last one, two, or three days of the calendar year, WeekOfTheYear returns 1 (the first week of the next calendar year).

Note: WeekOfTheYear uses the ISO 8601 standard definition of a week. That is, a week is considered to start on a Monday and end on a Sunday.
Note: WeekOfTheYear returns the same value as the WeekOf function.
Friecin 2005-04-15
  • 打赏
  • 举报
回复
#include <DateUtils.hpp>

ShowMessage( "当前是今年的第:" + AnsiString( WeekOfTheYear(Now()) ) + "周" );
木棉花大榕树 2005-04-15
  • 打赏
  • 举报
回复
不好意思,我用的是cb5,帮助里面没发现有这个函数?要include什么文件?能否给个简单例子?
laisf 2005-04-15
  • 打赏
  • 举报
回复
WeekOfTheYear

或者如果是ORACLE数据库,可以通过SQL取
select to_char(sysdate,'WW') from dual
icwin 2005-04-15
  • 打赏
  • 举报
回复
up
木棉花大榕树 2005-04-15
  • 打赏
  • 举报
回复
没找到,帮助里面没有,唉!
samchoy 2005-04-15
  • 打赏
  • 举报
回复
看看有没有WeekOf这个函数
木棉花大榕树 2005-04-15
  • 打赏
  • 举报
回复
[C++ Error] Unit1.h(10): E2209 Unable to open include file 'DateUtils.hpp'

编译报错,cb5好像没有这个文件,:(
Friecin 2005-04-14
  • 打赏
  • 举报
回复
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char *WeekName[7]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};

SYSTEMTIME Now,Tmp;
GetSystemTime(&Now);

Tmp.wYear=2222; //要查询的年份
Tmp.wMonth=12; //要查询的月份
Tmp.wDay=31; //要查询的日期
Tmp.wHour=1; //要查询的小时
Tmp.wMinute=1; //要查询的分数
Tmp.wSecond=1; //要查询的秒数
Tmp.wMilliseconds=1; //要查询的微秒

if(SetSystemTime(&Tmp)!=0)
{
GetSystemTime(&Tmp);
ShowMessage(WeekName[Tmp.wDayOfWeek]);
}
else
{
ShowMessage(GetLastError());//如果错误值是87的话,是参数设置有错。
}
SetSystemTime(&Now);
}

604

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder VCL组件使用和开发
社区管理员
  • VCL组件使用和开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧