Knowledge

C date and time functions

Source ๐Ÿ“

1557: 25: 1084: 205: 1077: 1397: 35: 1561: 198: 1378: 1287: 1070: 1496: 1013:"Rationale for American National Standard for Information Systems - Programming Language - C - Date and Time" 1516: 1468: 1583: 1526: 1511: 1217: 191: 117: 1473: 1202: 994: 599:
and related types were originally proposed by Markus Kuhn to provide a variety of time bases, but only
471: 254:
system command includes various formatting options. In 1989, the ANSI C standard is released including
87: 976: 1521: 1124: 1119: 1114: 341:). The value of the epoch is operating system dependent; 1900 and 1970 are often used. See RFC 868. 1501: 1212: 1160: 1093: 227: 112: 97: 42: 1364: 1339: 1382: 1324: 1029: 957: 1344: 132: 8: 1359: 1354: 1316: 1207: 102: 514: 1425: 1190: 1155: 223: 67: 603:
was accepted. The functionalities were, however, added to C++ in 2020 in std::chrono.
363: 1258: 1253: 1222: 1165: 1012: 937: 334: 127: 122: 92: 612: 479: 583: 444: 413: 303: 1369: 1329: 1237: 869:/* Print to stdout. ctime() has already added a terminating newline character. */ 571: 381: 555: 495: 460: 1542: 1387: 1349: 1275: 1175: 397: 347: 234:
acquisition, conversion between date formats, and formatted output to strings.
319: 1588: 1577: 1445: 1435: 1374: 230:
implementing date and time manipulation operations. They provide support for
539: 1415: 1180: 82: 1043: 1506: 1062: 326: 270: 231: 1150: 1129: 562: 429: 338: 932: 1450: 1440: 1420: 1265: 1232: 1170: 546: 354: 247: 177: 168: 150: 1134: 159: 1405: 1302: 1297: 1104: 1491: 1430: 1410: 1334: 1282: 1270: 278: 1292: 611:
The following C source code prints the current time to the
333:
value, number of seconds, (which is usually time since an
1109: 454:
object to custom wide string textual representation
549:time type: year, month, day, hour, minute, second 266:The C date and time operations are defined in the 1575: 391:object to a textual representation (deprecated) 561:arithmetic time type (typically time since the 489:value to calendar time expressed as local time 309:computes the difference in seconds between two 1078: 1030:open-std.org - Committee Draft -- May 6, 2005 435:converts a string with time information to a 370:returns a calendar time based on a time base 199: 520:number of processor clock ticks per second 1092: 1085: 1071: 842:"Failure to convert the current time. 206: 192: 749:"Failure to obtain the current time. 921:Current time is Thu Sep 15 21:18:23 2016 423:object to custom textual representation 261: 1041: 1576: 1066: 977:"PWB1 date system command - man page" 470:value to calendar time expressed as 18: 776:/* Convert to local time format. */ 258:and other date and time functions. 13: 589:time with seconds and nanoseconds 407:value to a textual representation 14: 1600: 1058: 508: 45:and remove advice or instruction. 1556: 1555: 222:are a group of functions in the 23: 959:ISO/IEC 9899:1999 specification 360: 1035: 1023: 1005: 987: 969: 950: 887:"Current time is %s" 1: 943: 501:converts calendar time to a 476: 357:associated with the process 7: 995:"date.c sourcecode of PWB1" 926: 580: 441: 426: 410: 295: 10: 1605: 1469:Compatibility of C and C++ 1044:"Modernized API for ISO C" 677:/* Obtain current time. */ 606: 577:process running time type 568: 472:Coordinated Universal Time 373: 242:The format string used in 237: 1551: 1535: 1482: 1459: 1396: 1315: 1246: 1198: 1189: 1143: 1100: 600: 596: 552: 534: 509: 492: 457: 374: 296: 220:C date and time functions 918: 617: 394: 344: 250:, released in 1977. Its 246:traces back to at least 88:Character classification 316: 1474:Comparison with Pascal 1094:C programming language 613:standard output stream 228:C programming language 533: 262:Overview of functions 141:Miscellaneous headers 16:Library of C programs 355:processor tick count 325:returns the current 43:rewrite this article 965:. p. 351, ยง 7.32.2. 1584:C standard library 1017:www.lysator.liu.se 530:time base for UTC 327:time of the system 133:Alternative tokens 68:C standard library 1571: 1570: 1311: 1310: 938:Year 2038 problem 593: 592: 216: 215: 118:Memory allocation 103:File input/output 60: 59: 36:a manual or guide 1596: 1559: 1558: 1196: 1195: 1191:Standard library 1087: 1080: 1073: 1064: 1063: 1052: 1051: 1039: 1033: 1027: 1021: 1020: 1009: 1003: 1002: 991: 985: 984: 973: 967: 966: 964: 954: 922: 912: 909: 906: 903: 900: 897: 894: 891: 888: 885: 882: 879: 876: 873: 870: 867: 864: 861: 858: 855: 852: 849: 846: 843: 840: 837: 834: 831: 828: 825: 822: 819: 816: 813: 810: 807: 804: 801: 798: 795: 792: 789: 786: 783: 780: 777: 774: 771: 768: 765: 762: 759: 756: 753: 750: 747: 744: 741: 738: 735: 732: 729: 726: 723: 720: 717: 714: 711: 708: 705: 702: 699: 696: 693: 690: 687: 684: 681: 678: 675: 672: 669: 666: 663: 660: 657: 654: 651: 648: 645: 642: 639: 636: 633: 630: 629:<stdlib.h> 627: 624: 621: 602: 598: 586: 574: 558: 542: 527: 517: 504: 498: 488: 482: 469: 463: 453: 447: 438: 432: 422: 416: 406: 400: 390: 384: 366: 350: 337:, typically the 332: 322: 312: 306: 284: 283: 276: 269: 257: 253: 245: 224:standard library 208: 201: 194: 181: 172: 163: 154: 64: 63: 55: 52: 46: 34:is written like 27: 26: 19: 1604: 1603: 1599: 1598: 1597: 1595: 1594: 1593: 1574: 1573: 1572: 1567: 1547: 1531: 1484: 1478: 1462:other languages 1461: 1460:Comparison with 1455: 1392: 1330:Borland Turbo C 1307: 1247:Implementations 1242: 1185: 1139: 1096: 1091: 1061: 1056: 1055: 1040: 1036: 1028: 1024: 1011: 1010: 1006: 993: 992: 988: 975: 974: 970: 962: 956: 955: 951: 946: 929: 924: 923: 920: 916:The output is: 914: 913: 910: 907: 904: 901: 898: 895: 892: 889: 886: 883: 880: 877: 874: 871: 868: 865: 862: 859: 856: 853: 850: 847: 844: 841: 838: 835: 832: 829: 826: 823: 820: 817: 814: 811: 808: 805: 802: 799: 796: 793: 790: 787: 784: 781: 778: 775: 772: 769: 766: 763: 760: 757: 754: 751: 748: 745: 742: 739: 736: 733: 730: 727: 724: 721: 718: 715: 712: 709: 706: 703: 700: 697: 694: 691: 688: 685: 682: 679: 676: 673: 670: 667: 664: 661: 658: 655: 652: 649: 646: 643: 640: 637: 635:<stdio.h> 634: 631: 628: 625: 622: 619: 609: 582: 570: 554: 538: 525: 513: 502: 494: 486: 478: 467: 459: 451: 443: 436: 428: 420: 412: 404: 396: 388: 380: 376: 362: 346: 330: 318: 310: 302: 298: 274: 267: 264: 255: 251: 243: 240: 212: 175: 166: 157: 148: 123:Process control 56: 50: 47: 40: 28: 24: 17: 12: 11: 5: 1602: 1592: 1591: 1586: 1569: 1568: 1566: 1565: 1552: 1549: 1548: 1546: 1545: 1543:Dennis Ritchie 1539: 1537: 1533: 1532: 1530: 1529: 1524: 1519: 1514: 1509: 1504: 1499: 1494: 1488: 1486: 1480: 1479: 1477: 1476: 1471: 1465: 1463: 1457: 1456: 1454: 1453: 1448: 1443: 1438: 1433: 1428: 1423: 1418: 1413: 1408: 1402: 1400: 1394: 1393: 1391: 1390: 1385: 1372: 1367: 1362: 1357: 1352: 1347: 1342: 1337: 1332: 1327: 1321: 1319: 1313: 1312: 1309: 1308: 1306: 1305: 1300: 1295: 1290: 1285: 1280: 1279: 1278: 1268: 1263: 1262: 1261: 1250: 1248: 1244: 1243: 1241: 1240: 1235: 1230: 1225: 1220: 1218:Dynamic memory 1215: 1210: 1205: 1199: 1193: 1187: 1186: 1184: 1183: 1178: 1173: 1168: 1163: 1158: 1153: 1147: 1145: 1141: 1140: 1138: 1137: 1132: 1127: 1122: 1117: 1112: 1107: 1101: 1098: 1097: 1090: 1089: 1082: 1075: 1067: 1060: 1059:External links 1057: 1054: 1053: 1034: 1022: 1004: 986: 968: 948: 947: 945: 942: 941: 940: 935: 928: 925: 919: 623:<time.h> 618: 608: 605: 591: 590: 587: 579: 578: 575: 567: 566: 559: 551: 550: 543: 536: 532: 531: 528: 522: 521: 518: 515:CLOCKS_PER_SEC 511: 507: 506: 499: 491: 490: 483: 475: 474: 464: 456: 455: 448: 440: 439: 433: 425: 424: 417: 409: 408: 401: 393: 392: 385: 378: 372: 371: 368: 359: 358: 351: 343: 342: 323: 315: 314: 307: 300: 294: 293: 290: 287: 263: 260: 239: 236: 214: 213: 211: 210: 203: 196: 188: 185: 184: 183: 182: 173: 164: 155: 143: 142: 138: 137: 136: 135: 130: 125: 120: 115: 110: 105: 100: 95: 90: 85: 77: 76: 75:General topics 72: 71: 58: 57: 31: 29: 22: 15: 9: 6: 4: 3: 2: 1601: 1590: 1587: 1585: 1582: 1581: 1579: 1564: 1563: 1554: 1553: 1550: 1544: 1541: 1540: 1538: 1534: 1528: 1525: 1523: 1520: 1518: 1515: 1513: 1510: 1508: 1505: 1503: 1500: 1498: 1495: 1493: 1490: 1489: 1487: 1481: 1475: 1472: 1470: 1467: 1466: 1464: 1458: 1452: 1449: 1447: 1446:Visual Studio 1444: 1442: 1439: 1437: 1436:GNOME Builder 1434: 1432: 1429: 1427: 1424: 1422: 1419: 1417: 1414: 1412: 1409: 1407: 1404: 1403: 1401: 1399: 1395: 1389: 1386: 1384: 1380: 1376: 1375:Visual Studio 1373: 1371: 1368: 1366: 1363: 1361: 1358: 1356: 1353: 1351: 1348: 1346: 1343: 1341: 1338: 1336: 1333: 1331: 1328: 1326: 1323: 1322: 1320: 1318: 1314: 1304: 1301: 1299: 1296: 1294: 1291: 1289: 1286: 1284: 1281: 1277: 1274: 1273: 1272: 1269: 1267: 1264: 1260: 1257: 1256: 1255: 1252: 1251: 1249: 1245: 1239: 1236: 1234: 1231: 1229: 1226: 1224: 1221: 1219: 1216: 1214: 1211: 1209: 1206: 1204: 1201: 1200: 1197: 1194: 1192: 1188: 1182: 1179: 1177: 1174: 1172: 1169: 1167: 1164: 1162: 1159: 1157: 1154: 1152: 1149: 1148: 1146: 1142: 1136: 1133: 1131: 1128: 1126: 1123: 1121: 1118: 1116: 1113: 1111: 1108: 1106: 1103: 1102: 1099: 1095: 1088: 1083: 1081: 1076: 1074: 1069: 1068: 1065: 1049: 1045: 1042:Markus Kuhn. 1038: 1031: 1026: 1018: 1014: 1008: 1000: 996: 990: 982: 978: 972: 961: 960: 953: 949: 939: 936: 934: 931: 930: 917: 893:c_time_string 806:c_time_string 779:c_time_string 671:c_time_string 616: 614: 604: 588: 585: 581: 576: 573: 569: 564: 560: 557: 553: 548: 544: 541: 537: 529: 524: 523: 519: 516: 512: 500: 497: 493: 484: 481: 477: 473: 465: 462: 458: 449: 446: 442: 434: 431: 427: 418: 415: 411: 402: 399: 395: 386: 383: 379: 369: 365: 361: 356: 352: 349: 345: 340: 336: 328: 324: 321: 317: 308: 305: 301: 299:manipulation 291: 288: 286: 285: 282: 280: 272: 259: 249: 235: 233: 229: 225: 221: 209: 204: 202: 197: 195: 190: 189: 187: 186: 179: 174: 170: 165: 161: 156: 152: 147: 146: 145: 144: 140: 139: 134: 131: 129: 126: 124: 121: 119: 116: 114: 111: 109: 106: 104: 101: 99: 96: 94: 91: 89: 86: 84: 81: 80: 79: 78: 74: 73: 69: 66: 65: 62: 54: 44: 39: 37: 32:This article 30: 21: 20: 1560: 1416:Code::Blocks 1388:Watcom C/C++ 1227: 1176:Preprocessor 1156:Header files 1048:cl.cam.ac.uk 1047: 1037: 1025: 1016: 1007: 999:www.tuhs.org 998: 989: 981:www.tuhs.org 980: 971: 958: 952: 915: 905:EXIT_SUCCESS 860:EXIT_FAILURE 794:current_time 767:EXIT_FAILURE 704:current_time 680:current_time 659:current_time 610: 594: 545:broken-down 377:conversions 364:timespec_get 292:Description 265: 248:PWB/UNIX 1.0 241: 219: 217: 113:Localization 107: 61: 51:October 2014 48: 41:Please help 33: 1507:Objective-C 1288:Windows CRT 485:converts a 466:converts a 450:converts a 419:converts a 403:converts a 387:converts a 289:Identifier 271:header file 98:Mathematics 1578:Categories 1483:Descendant 1355:Norcroft C 1181:Data types 1130:Embedded C 944:References 563:Unix epoch 510:Constants 353:returns a 339:Unix epoch 277:header in 83:Data types 1485:languages 1317:Compilers 1259:libhybris 1161:Operators 1151:Functions 933:Unix time 540:struct tm 480:localtime 452:struct tm 437:struct tm 421:struct tm 389:struct tm 108:Date/time 1562:Category 1536:Designer 1451:NetBeans 1441:KDevelop 1421:CodeLite 1266:dietlibc 1233:Variadic 1208:File I/O 1144:Features 1032:page 355 927:See also 632:#include 626:#include 620:#include 601:TIME_UTC 597:timespec 584:timespec 547:calendar 526:TIME_UTC 445:wcsftime 430:strptime 414:strftime 304:difftime 256:strftime 244:strftime 178:stdarg.h 169:setjmp.h 151:assert.h 1426:Eclipse 1379:Express 1135:MISRA C 830:fprintf 737:fprintf 607:Example 572:clock_t 505:value. 382:asctime 313:values 238:History 226:of the 160:errno.h 128:Signals 93:Strings 1406:Anjuta 1303:uClibc 1298:Newlib 1276:EGLIBC 1254:Bionic 1223:String 1171:Syntax 1166:String 1105:ANSI C 881:printf 848:" 836:stderr 755:" 743:stderr 713:time_t 656:time_t 556:time_t 535:Types 503:time_t 496:mktime 487:time_t 468:time_t 461:gmtime 405:time_t 375:Format 367:(C11) 331:time_t 311:time_t 268:time.h 70:(libc) 1517:Limbo 1431:Geany 1411:CLion 1335:Clang 1283:klibc 1271:glibc 1238:POSIX 963:(PDF) 791:& 785:ctime 398:ctime 348:clock 335:epoch 329:as a 275:ctime 1589:Time 1527:Vala 1512:Alef 1398:IDEs 1365:SDCC 1293:musl 1228:Time 1213:Math 1203:Char 899:exit 875:void 854:exit 824:void 812:NULL 761:exit 731:void 692:NULL 686:time 665:char 647:void 641:main 595:The 320:time 297:Time 252:date 232:time 218:The 180:> 176:< 171:> 167:< 162:> 158:< 153:> 149:< 1492:C++ 1383:C++ 1370:TCC 1360:PCC 1350:LCC 1345:ICC 1340:GCC 1325:ACK 1125:C23 1120:C17 1115:C11 1110:C99 638:int 281:). 279:C++ 1580:: 1522:Go 1497:C# 1381:, 1377:, 1046:. 1015:. 997:. 979:. 908:); 896:); 863:); 851:); 845:\n 809:== 800:if 797:); 770:); 758:); 752:\n 722:)) 719:-1 710:(( 707:== 698:if 695:); 615:. 565:) 1502:D 1086:e 1079:t 1072:v 1050:. 1019:. 1001:. 983:. 911:} 902:( 890:, 884:( 878:) 872:( 866:} 857:( 839:, 833:( 827:) 821:( 818:{ 815:) 803:( 788:( 782:= 773:} 764:( 746:, 740:( 734:) 728:( 725:{ 716:) 701:( 689:( 683:= 674:; 668:* 662:; 653:{ 650:) 644:( 273:( 207:e 200:t 193:v 53:) 49:( 38:.

Index

a manual or guide
rewrite this article
C standard library
Data types
Character classification
Strings
Mathematics
File input/output
Date/time
Localization
Memory allocation
Process control
Signals
Alternative tokens
assert.h
errno.h
setjmp.h
stdarg.h
v
t
e
standard library
C programming language
time
PWB/UNIX 1.0
header file
C++
difftime
time
time of the system

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.

โ†‘