| |

VerySource

 Forgot password?
 Register
Search
View: 904|Reply: 6

A question about time in C language, eager to enlighten me

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

Post time: 2020-3-16 12:00:01
| Show all posts |Read mode
I use the time (&t) function under Turboc and the system correct time is completely wrong. Is there any way to solve it?
Reply

Use magic Report

0

Threads

73

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 Invalid IP Address

Post time: 2020-6-15 22:30:01
| Show all posts
How do you know it's wrong and how do you print it? Orally?
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

 Author| Post time: 2020-6-16 09:30:01
| Show all posts
I just printed it and the screen shows: Fri Qct 29 12:57:46 1982
And I checked my system time and it was correct without any problems.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-30 17:45:01
| Show all posts
#include <time.h>
#include <stdio.h>
#include <dos.h>

int main(void)
{
   time_t t;

   t = time(NULL);
   printf(ctime(&t));
   return 0;
}
Reply

Use magic Report

0

Threads

24

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-1 13:15:01
| Show all posts
Funny, right?
Reply

Use magic Report

0

Threads

24

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-1 14:30:01
| Show all posts
time remark is

get the system time
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

 Author| Post time: 2020-7-7 10:30:01
| Show all posts
Thank you all, I have found the answer

# include <stdio.h>
  # include <time.h>
   
  viod printtime(viod)
  {
        struct tm* ptime;
        time_t ltime;
            
        time (&ltime);
        ptime = localtime (&ltime );
        printf( "%02d:%02d:%02d",
                        ptime->tm_hour,ptime->tm_min,ptime->tm_sec );
  };
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list