[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

GetLocalTime in VC++

Posted on 2001-09-16
9
Medium Priority
?
1,577 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
Technology Partners: 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 440 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

650 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