CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    May 2012
    Posts
    16

    [RESOLVED] date & time (non static) in statusbar

    hi all,

    I'm trying to place the date and time in my statusbar, but the time does not change and remains static, I think I need a loop or something, I google it and found several ways to get time from my system, and this is the only one that works with 12h am-pm

    Code:
    //add time.h
    	struct tm newtime;
    	char am_pm []="am";
    	char t_buf [26];
    	__time64_t long_time;
    	errno_t err;
    
    	_time64 (&long_time);
    	err = _localtime64_s (&newtime, &long_time);
    
    	if (newtime. tm_hour>12)	strcpy_s (am_pm, sizeof (am_pm),"pm");
    	if (newtime. tm_hour>12)	newtime.tm_hour	-=12;
    	if (newtime. tm_hour==0)	newtime.tm_hour	 =12;
    	err = asctime_s (t_buf,26,&newtime);
    
    	wsprintf (t_buffer,"%.19s %s",t_buf, am_pm);
    	SendMessage (h_statusbar, SB_SETTEXT, 0, (LPARAM) t_buffer);
    Code:
    //more optimized
    	char am_pm []="am";
    	SYSTEMTIME slt;
    	GetLocalTime (&slt);
    	
    	if (slt.wHour>12)	strcpy_s (am_pm, sizeof (am_pm),"pm");
    	if (slt.wHour>12)	slt.wHour	-=12;
    	if (slt.wHour==0)	slt.wHour	 =12;
    
    	wsprintf (t_buffer,
    		"%02d/%02d/%d @ %02d:%02d:%02d %s",
    		slt.wDay, slt.wMonth,slt.wYear, 
    		slt.wHour,slt.wMinute,slt.wSecond,
    		am_pm);
    
    	SendMessage (h_statusbar, SB_SETTEXT, 0, (LPARAM) t_buffer);
    maybe is simple but can not get a function for that, I do not want to do it for me, just guide me or the name of a function and excuse my language, I'm from latin america ^^

    regards
    Last edited by v_nom70; December 13th, 2012 at 09:18 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured