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

  • SEARCH
  • Home
  • 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 8958973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:20:26+00:00 2026-06-15T15:20:26+00:00

I’ve got a problem. I need to get things like day of year, day

  • 0

I’ve got a problem.
I need to get things like day of year, day of month, month of year etc.
I use this code:

#include <stdio.h>
#include <time.h>
int main(void)
{    
    time_t liczba_sekund;
    struct tm strukt;
    time(&liczba_sekund);
    localtime_r(&liczba_sekund, &strukt); 
    printf("today is %d day of year\nmonth is %d, month's day %d\n", strukt.tm_yday+1, strukt.tm_mon+1, strukt.tm_mday); 
    return 0;
}

First thing: why does gcc -std=c99 -pedantic -Wall return this warning:

My input: gcc test_data.c -o test_data.out -std=c99 -pedantic -Wall

Output:

test_data.c: In function ‘main’:

test_data.c:11:3: warning: implicit declaration of function ‘localtime_r’ [-Wimplicit-function-declaration]

Second thing: how to make it work on windows? While trying to compile it using Dev-C, I got this:
https://i.stack.imgur.com/F8Qlx.jpg

@@EDIT ——————–
I have found an example for your localtime suggestion:

#include <stdio.h>
#include <time.h>

int main ()
{
    time_t time_raw_format;
    struct tm * ptr_time;

    time ( &time_raw_format );
    ptr_time = localtime ( &time_raw_format );
    printf ("Current local time and date: %s", asctime(ptr_time));
    return 0;
}

How can I change this to date format like this: 5.12.2012 or 5-12-2012? And how to get the day of the year?

I would love if the solution worked both on windows and linux.

  • 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-06-15T15:20:27+00:00Added an answer on June 15, 2026 at 3:20 pm

    localtime_r is not part of the C standard. Maybe you were looking for localtime?

    localtime_r is really available on many linux systems:

    Thread-safe versions asctime_r(), ctime_r(), gmtime_r() and localtime_r() are specified by SUSv2, and available since libc 5.2.5

    However, since it isn’t part of the standard you cannot use it on Windows.

    How can I change this to date format like this: 5.12.2012 or 5-12-2012? And how to get the day of the year?

    You have to use strftime instead of asctime:

    int main ()
    {
        time_t time_raw_format;
        struct tm * ptr_time;
        char buffer[50];
    
        time ( &time_raw_format );
        ptr_time = localtime ( &time_raw_format );
        if(strftime(buffer,50,"%d.%m.%Y",ptr_time) == 0){
            perror("Couldn't prepare formatted string");
        } else {
            printf ("Current local time and date: %s", buffer);
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is

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.