求时间函数,格式是:YYYYMMDD(如:20030926)

jourmen 2003-09-26 12:46:40
格式是YYYYMMDD(如:20030926)
标准库里的实现不了
谢谢!!!
...全文
125 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
我不懂电脑 2003-10-04
  • 打赏
  • 举报
回复
C++ Builder里
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime date = Now();

Edit1->Text = date.FormatString("YYYYMMDD");
}
我不懂电脑 2003-10-04
  • 打赏
  • 举报
回复
C++ Builder里
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime date = Now();

Edit1->Text = date.FormatString("YYYYMMDD");
}
Skt32 2003-10-04
  • 打赏
  • 举报
回复
char* GetCurrentDate()
{
static char szDate[30];
time_t long_time;
struct tm *newtime;

// get cur time
time(&long_time);
newtime = localtime(&long_time);

// year
sprintf(szDate, "%d%02d%02d",
newtime->tm_year +1900,
newtime->tm_mon +1,
newtime->tm_mday);

return szDate;
}




void main()
{
printf(GetCurrentDate());
}
msdner 2003-10-04
  • 打赏
  • 举报
回复
这个我也想知道,有谁知道吗?
msdner 2003-10-04
  • 打赏
  • 举报
回复
好像都不行啊,有没有程序实例呢?
Skt32 2003-10-04
  • 打赏
  • 举报
回复
char* CDemoDlg::GetCurrentDate()
{
static char szDate[30];
time_t long_time;
struct tm *newtime;

// get cur time
time(&long_time);
newtime = localtime(&long_time);

// year
sprintf(szDate, "%d%02d%02d",
newtime->tm_year +1900,
newtime->tm_mon +1,
newtime->tm_mday);

return szDate;
}
ZHENG017 2003-09-27
  • 打赏
  • 举报
回复
SYSTEMTIME stSystemTime;
GetLocalTime(&stSystemTime);
sprintf(chOut,"%04d%02d%02d",stSystemTime.wYear,stSystemTime.wMonth,stSystemTime.wDay);
darcymei 2003-09-26
  • 打赏
  • 举报
回复
The time function returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time, according to the system clock. The return value is stored in the location given by timer. This parameter may be NULL, in which case the return value is not stored.

Example

/* TIMES.C illustrates various time and date functions including:
* time _ftime ctime asctime
* localtime gmtime mktime _tzset
* _strtime _strdate strftime
*
* Also the global variable:
* _tzname
*/

#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>

void main()
{
char tmpbuf[128], ampm[] = "AM";
time_t ltime;
struct _timeb tstruct;
struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 };

/* Set time zone from TZ environment variable. If TZ is not set,
* the operating system is queried to obtain the default value
* for the variable.
*/
_tzset();

/* Display operating system-style date and time. */
_strtime( tmpbuf );
printf( "OS time:\t\t\t\t%s\n", tmpbuf );
_strdate( tmpbuf );
printf( "OS date:\t\t\t\t%s\n", tmpbuf );

/* Get UNIX-style time and display as number and string. */
time( <ime );
printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );
printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) );

/* Display UTC. */
gmt = gmtime( <ime );
printf( "Coordinated universal time:\t\t%s", asctime( gmt ) );

/* Convert to time structure and adjust for PM if necessary. */
today = localtime( <ime );
if( today->tm_hour > 12 )
{
strcpy( ampm, "PM" );
today->tm_hour -= 12;
}
if( today->tm_hour == 0 ) /* Adjust if midnight hour. */
today->tm_hour = 12;

/* Note how pointer addition is used to skip the first 11
* characters and printf is used to trim off terminating
* characters.
*/
printf( "12-hour time:\t\t\t\t%.8s %s\n",
asctime( today ) + 11, ampm );

/* Print additional time information. */
_ftime( &tstruct );
printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm );
printf( "Zone difference in seconds from UTC:\t%u\n",
tstruct.timezone );
printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] );
printf( "Daylight savings:\t\t\t%s\n",
tstruct.dstflag ? "YES" : "NO" );

/* Make time for noon on Christmas, 1993. */
if( mktime( &xmas ) != (time_t)-1 )
printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) );

/* Use time structure to build a customized time string. */
today = localtime( <ime );

/* Use strftime to build a customized time string. */
strftime( tmpbuf, 128,
"Today is %A, day %d of %B in the year %Y.\n", today );
printf( tmpbuf );
}



Output

OS time: 21:51:03
OS date: 05/03/94
Time in seconds since UTC 1/1/70: 768027063
UNIX time and date: Tue May 03 21:51:03 1994
Coordinated universal time: Wed May 04 04:51:03 1994
12-hour time: 09:51:03 PM
Plus milliseconds: 279
Zone difference in seconds from UTC: 480
Time zone name:
Daylight savings: YES
Christmas Sat Dec 25 12:00:00 1993

Today is Tuesday, day 03 of May in the year 1994.

lzy125vc 2003-09-26
  • 打赏
  • 举报
回复
%Y-%m-%d

24,860

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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