Solved

GetLocalTime in VC++

Posted on 2001-09-16
9
1,565 Views
Last Modified: 2007-11-27
Hello all -

In VC++, the GetLocalTime() function - is there any way to break up the hours or minutes into their individual int components.

Ex: st.wHour may equal 12... and st.wMinute may equal 23.

I want to return in the wHour the 1 as one variable and the 2 as another.

In the wMinute return the 2 and the 3 as two seperate int variables.

and if it was 1:02 return (0 and 1 for hour) and (0 and 2 for minutes)

Thanks for trying to help!
0
Comment
Question by:salibes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 1

Expert Comment

by:kuchnaheen
ID: 6486084
i suggested using following combintion of functions at ur other question...

GetLocalTime(&st)
  GetDateFormat(0,DATE_SHORTDATE,&st,NULL,date,sizeof(date));
  GetTimeFormat(0,LOCALE_NOUSEROVERRIDE,&st,NULL,time,sizeof(time));

after getting the time in chraracter string it is really easy to exract the individual values...u can use strtok on ':' or even can use CString for the purpose...

let me know if u need the code...
0
 

Author Comment

by:salibes
ID: 6486095
Thank you so much.  I do need the code if you don't mind because I'm not exactly sure how to extract the values.  I really appreciate it.
0
 

Author Comment

by:salibes
ID: 6486102
Thank you so much.  I do need the code if you don't mind because I'm not exactly sure how to extract the values.  I really appreciate it.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:kuchnaheen
ID: 6486133


okay with strtok u will go something like

this is how will u get hours n minutes out of the string...
  SYSTEMTIME st;
  char time[20];
  char *token;
  int hms[3];
  int count =0;
  char AMPM[3];
this is what i do to make sure that locl variables dont mess

  memset(time,0,20);
  memset(AMPM,0,3);
get the local time
GetLocalTime(&st);
GetTimeFormat(0,LOCALE_NOUSEROVERRIDE,&st,NULL,time,sizeof(time));

//tokenize the time string

token = strtok( time, " :" );
  while( token != NULL )
  {
     if(count<3)
       {
            hms[count]=atoi(token);
              cout<<hms[count]<<endl;
        }
       else
       {
            strcpy(AMPM,token);
              cout<<AMPM;
       }
       //increase the count
       count++;
       // Get next token
       token = strtok( NULL, " :" );
  }

continuous
0
 
LVL 1

Accepted Solution

by:
kuchnaheen earned 110 total points
ID: 6486144
n come on guy... i have misreaad ur question u have hours n minutes... no need of my stuff ... u just need / and % opertor...like

int h1,h2,m1,m2,wHour,wMin;
//initiliaze all of them
...
...

// u have wHour=12 n wMin =23

//now
h1=whour/10;
h2=wHour%10;

m1=wMin/10;
m2=wMin%10;

//now u have 1 in h1 n 2 in h2 and same for minutes
//do what ever u wanna do with these

enjoy..........
0
 

Author Comment

by:salibes
ID: 6486151
OH!

Thank you so much for all your help. That last division post did it.  I owe you one.  Let me know if the grade came out alright.

Thanks again,
salibes
0
 
LVL 1

Expert Comment

by:kuchnaheen
ID: 6486156
ignore my first n second cooment....they have nothing to do with ur problem...the code i have given in second comment is rather a silly effort as u can have hours n minutes directlyy from systime struct...the only thing it gives u is the AM/PM solution .... but this problem can be easily solved bu other means ... no need of this string manipulation...
0
 
LVL 1

Expert Comment

by:kuchnaheen
ID: 6486163
ignore my first n second cooment....they have nothing to do with ur problem...the code i have given in second comment is rather a silly effort as u can have hours n minutes directlyy from systime struct...the only thing it gives u is the AM/PM solution .... but this problem can be easily solved bu other means ... no need of this string manipulation...
0
 
LVL 1

Expert Comment

by:kuchnaheen
ID: 6486180
okayyyyy...thanx

the grade is alrihght...there is nothing above A;)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question