time formatting


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: time formatting

  1. #1
    Join Date
    Oct 2006
    Posts
    1

    time formatting

    I am doing a homework problem that involves converting military time from an imput file to civilian time. To do this I have used two variable to define the hours and minutes (H and M).

    My problem arises when the minutes is less than 10. An example: 6:9 P.M. This time is obviously meant to display 6:09 P.M., but I don't know how to make it do so without setting up multiple loops (M<10){ cout<<H<<":"<<"0"<<M<<endl;}

    In short, I want to know how to decalre a varible to be atleast 2 digits, thus filling in zeros whenever the value is less than 10.
    9---->09

    Thanks for any help,
    Nate

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    You don't need a special variable here. Simply check the that minutes variable is smaller than 10, and if so print 0 before the minutes. It's best to format the hours, minutes and seconds as separate strings (not digits) and then dispaly these three strings using cout.
    Danny Kalev

Similar Threads

  1. Replies: 8
    Last Post: 08-27-2006, 07:44 PM
  2. Need help and GMT0 time transform local time?
    By tianming.hu in forum Java
    Replies: 0
    Last Post: 05-18-2006, 04:50 AM
  3. query tuning
    By dhaya in forum Database
    Replies: 11
    Last Post: 08-25-2003, 05:24 PM
  4. What's the right time????
    By Coilin Riley in forum Java
    Replies: 2
    Last Post: 05-31-2001, 03:26 PM
  5. Replies: 0
    Last Post: 08-14-2000, 10:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center