Solved

GetLocalTime in VC++

Posted on 2001-09-16
9
1,560 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

706 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

19 Experts available now in Live!

Get 1:1 Help Now