Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1009243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:53:40+00:00 2026-05-16T08:53:40+00:00

I have the below program to obtain current date and time. int main(void) {

  • 0

I have the below program to obtain current date and time.

int main(void)  
{  
  time_t result;  
  result = time(NULL);  
  struct tm* brokentime = localtime(&result);  
  printf("%s", asctime(brokentime));  
  return(0);  
}

And the output of the program is as follows :

Tue Aug 24 01:02:41 2010

How do I retrieve only the hour value say 01 from the above ?
Or is there any other system call where the currect hour of the system can be obtained ? I need to take an action based on this.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:53:40+00:00Added an answer on May 16, 2026 at 8:53 am

    If you want it as a number (and not a string), then just access the appropriate field in the brokentime structure:

    time_t result;  
    result = time(NULL);  
    struct tm* brokentime = localtime(&result);  
    int h = brokentime->tm_hour; /* h now contains the hour (1) */
    

    If you want it as a string, then you will have to format the string yourself (rather than using asctime):

    time_t result;  
    result = time(NULL);  
    struct tm* brokentime = localtime(&result);  
    char hour_str[3];
    
    strftime(hour_str, sizeof(hour_str), "%H", brokentime);
    /* hour_str now contains the hour ("01") */
    

    Use %I instead of %H to get 12-hour time instead of 24-hour time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 543k
  • Answers 543k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Suppose you receive data over a socket connection. You will… May 17, 2026 at 6:42 am
  • Editorial Team
    Editorial Team added an answer That code runs and compiles fine in my environment, gcc… May 17, 2026 at 6:42 am
  • Editorial Team
    Editorial Team added an answer GLib.Timeout - Answered by mhutch on IRC. May 17, 2026 at 6:42 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have written a sample program below. class Program { static int x =
I have seen many programs consisting of structures like the one below typedef struct
I have the below code in stdafx.h. using namespace std; typedef struct { DWORD
I have the below mail program. The problem is mail program runs successfully but
I have the below simple program using boost threads, what would be the changes
I have a query based on the below program - char ch; ch =
I am very new to jQuery and javascript programming. I have a program below
I have written the java code below, which executes another java program named Newsworthy_RB.
In the program below i initiliaze i to 255 Thus in Binary we have:
I have below a list of text, it is from a popular online game

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.