Solved

GetLocalTime in VC++

Posted on 2001-09-16
9
1,568 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

724 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