Solved

GetLocalTime in VC++

Posted on 2001-09-16
9
1,561 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now