1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
|
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Timing Utilities (GNU Octave (version 10.3.0))</title>
<meta name="description" content="Timing Utilities (GNU Octave (version 10.3.0))">
<meta name="keywords" content="Timing Utilities (GNU Octave (version 10.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="System-Utilities.html" rel="up" title="System Utilities">
<link href="Filesystem-Utilities.html" rel="next" title="Filesystem Utilities">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
ul.mark-bullet {list-style-type: disc}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<div class="section-level-extent" id="Timing-Utilities">
<div class="nav-panel">
<p>
Next: <a href="Filesystem-Utilities.html" accesskey="n" rel="next">Filesystem Utilities</a>, Up: <a href="System-Utilities.html" accesskey="u" rel="up">System Utilities</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Timing-Utilities-1"><span>36.1 Timing Utilities<a class="copiable-link" href="#Timing-Utilities-1"> ¶</a></span></h3>
<p>Octave’s core set of functions for manipulating time values are
patterned after the corresponding functions from the standard C library.
Several of these functions use a data structure for time that includes
the following elements:
</p>
<dl class="table">
<dt><code class="code">usec</code></dt>
<dd><p>Microseconds after the second (0-999999).
</p>
</dd>
<dt><code class="code">sec</code></dt>
<dd><p>Seconds after the minute (0-60). This number can be 60 to account
for leap seconds.
</p>
</dd>
<dt><code class="code">min</code></dt>
<dd><p>Minutes after the hour (0-59).
</p>
</dd>
<dt><code class="code">hour</code></dt>
<dd><p>Hours since midnight (0-23).
</p>
</dd>
<dt><code class="code">mday</code></dt>
<dd><p>Day of the month (1-31).
</p>
</dd>
<dt><code class="code">mon</code></dt>
<dd><p>Months since January (0-11).
</p>
</dd>
<dt><code class="code">year</code></dt>
<dd><p>Years since 1900.
</p>
</dd>
<dt><code class="code">wday</code></dt>
<dd><p>Days since Sunday (0-6).
</p>
</dd>
<dt><code class="code">yday</code></dt>
<dd><p>Days since January 1 (0-365).
</p>
</dd>
<dt><code class="code">isdst</code></dt>
<dd><p>Daylight saving time flag.
</p>
</dd>
<dt><code class="code">gmtoff</code></dt>
<dd><p>Seconds offset from UTC.
</p>
</dd>
<dt><code class="code">zone</code></dt>
<dd><p>Time zone.
</p></dd>
</dl>
<p>In the descriptions of the following functions, this structure is
referred to as a <var class="var">tm_struct</var>.
</p>
<a class="anchor" id="XREFtime"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-time"><span><code class="def-type"><var class="var">seconds</var> =</code> <strong class="def-name">time</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-time"> ¶</a></span></dt>
<dd><p>Return the current time as the number of seconds since the epoch.
</p>
<p>The epoch is referenced to 00:00:00 UTC (Coordinated Universal Time) 1 Jan
1970. For example, on Monday February 17, 1997 at 07:15:06 UTC, the value
returned by <code class="code">time</code> was 856163706.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFstrftime">strftime</a>, <a class="ref" href="#XREFstrptime">strptime</a>, <a class="ref" href="#XREFlocaltime">localtime</a>, <a class="ref" href="#XREFgmtime">gmtime</a>, <a class="ref" href="#XREFmktime">mktime</a>, <a class="ref" href="#XREFnow">now</a>, <a class="ref" href="#XREFdate">date</a>, <a class="ref" href="#XREFclock">clock</a>, <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatestr">datestr</a>, <a class="ref" href="#XREFdatevec">datevec</a>, <a class="ref" href="#XREFcalendar">calendar</a>, <a class="ref" href="#XREFweekday">weekday</a>.
</p></dd></dl>
<a class="anchor" id="XREFnow"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-now"><span><code class="def-type">t =</code> <strong class="def-name">now</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-now"> ¶</a></span></dt>
<dd><p>Return the current local date/time as a serial day number
(see <a class="pxref" href="#XREFdatenum"><code class="code">datenum</code></a>).
</p>
<p>The integral part, <code class="code">floor (now)</code> corresponds to the number of days
between today and Jan 1, 0000.
</p>
<p>The fractional part, <code class="code">rem (now, 1)</code> corresponds to the current time.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFclock">clock</a>, <a class="ref" href="#XREFdate">date</a>, <a class="ref" href="#XREFdatenum">datenum</a>.
</p></dd></dl>
<a class="anchor" id="XREFctime"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-ctime"><span><code class="def-type"><var class="var">str</var> =</code> <strong class="def-name">ctime</strong> <code class="def-code-arguments">(<var class="var">t</var>)</code><a class="copiable-link" href="#index-ctime"> ¶</a></span></dt>
<dd><p>Convert a value returned from <code class="code">time</code> (or any other non-negative
integer), to the local time and return a string of the same form as
<code class="code">asctime</code>.
</p>
<p>The function <code class="code">ctime (time)</code> is equivalent to
<code class="code">asctime (localtime (time))</code>. For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">ctime (time ())
⇒ "Mon Feb 17 01:15:06 1997\n"
</pre></div></div>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFasctime">asctime</a>, <a class="ref" href="#XREFtime">time</a>, <a class="ref" href="#XREFlocaltime">localtime</a>.
</p></dd></dl>
<a class="anchor" id="XREFgmtime"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-gmtime"><span><code class="def-type"><var class="var">tm_struct</var> =</code> <strong class="def-name">gmtime</strong> <code class="def-code-arguments">(<var class="var">t</var>)</code><a class="copiable-link" href="#index-gmtime"> ¶</a></span></dt>
<dd><p>Given a value returned from <code class="code">time</code>, or any non-negative integer,
return a time structure corresponding to UTC (Coordinated Universal Time).
</p>
<p>For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">gmtime (time ())
⇒ {
usec = 0
sec = 6
min = 15
hour = 7
mday = 17
mon = 1
year = 97
wday = 1
yday = 47
isdst = 0
gmtoff = 0
zone = GMT
}
</pre></div></div>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFstrftime">strftime</a>, <a class="ref" href="#XREFstrptime">strptime</a>, <a class="ref" href="#XREFlocaltime">localtime</a>, <a class="ref" href="#XREFmktime">mktime</a>, <a class="ref" href="#XREFtime">time</a>, <a class="ref" href="#XREFnow">now</a>, <a class="ref" href="#XREFdate">date</a>, <a class="ref" href="#XREFclock">clock</a>, <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatestr">datestr</a>, <a class="ref" href="#XREFdatevec">datevec</a>, <a class="ref" href="#XREFcalendar">calendar</a>, <a class="ref" href="#XREFweekday">weekday</a>.
</p></dd></dl>
<a class="anchor" id="XREFlocaltime"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-localtime"><span><code class="def-type"><var class="var">tm_struct</var> =</code> <strong class="def-name">localtime</strong> <code class="def-code-arguments">(<var class="var">t</var>)</code><a class="copiable-link" href="#index-localtime"> ¶</a></span></dt>
<dd><p>Given a value returned from <code class="code">time</code>, or any non-negative integer,
return a time structure corresponding to the local time zone.
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">localtime (time ())
⇒ {
usec = 0
sec = 6
min = 15
hour = 1
mday = 17
mon = 1
year = 97
wday = 1
yday = 47
isdst = 0
gmtoff = -21600
zone = CST
}
</pre></div></div>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFstrftime">strftime</a>, <a class="ref" href="#XREFstrptime">strptime</a>, <a class="ref" href="#XREFgmtime">gmtime</a>, <a class="ref" href="#XREFmktime">mktime</a>, <a class="ref" href="#XREFtime">time</a>, <a class="ref" href="#XREFnow">now</a>, <a class="ref" href="#XREFdate">date</a>, <a class="ref" href="#XREFclock">clock</a>, <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatestr">datestr</a>, <a class="ref" href="#XREFdatevec">datevec</a>, <a class="ref" href="#XREFcalendar">calendar</a>, <a class="ref" href="#XREFweekday">weekday</a>.
</p></dd></dl>
<a class="anchor" id="XREFmktime"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-mktime"><span><code class="def-type"><var class="var">seconds</var> =</code> <strong class="def-name">mktime</strong> <code class="def-code-arguments">(<var class="var">tm_struct</var>)</code><a class="copiable-link" href="#index-mktime"> ¶</a></span></dt>
<dd><p>Convert a time structure corresponding to the local time to the number of
seconds since the epoch.
</p>
<p>For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">mktime (localtime (time ()))
⇒ 856163706
</pre></div></div>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFstrftime">strftime</a>, <a class="ref" href="#XREFstrptime">strptime</a>, <a class="ref" href="#XREFlocaltime">localtime</a>, <a class="ref" href="#XREFgmtime">gmtime</a>, <a class="ref" href="#XREFtime">time</a>, <a class="ref" href="#XREFnow">now</a>, <a class="ref" href="#XREFdate">date</a>, <a class="ref" href="#XREFclock">clock</a>, <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatestr">datestr</a>, <a class="ref" href="#XREFdatevec">datevec</a>, <a class="ref" href="#XREFcalendar">calendar</a>, <a class="ref" href="#XREFweekday">weekday</a>.
</p></dd></dl>
<a class="anchor" id="XREFasctime"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-asctime"><span><code class="def-type"><var class="var">str</var> =</code> <strong class="def-name">asctime</strong> <code class="def-code-arguments">(<var class="var">tm_struct</var>)</code><a class="copiable-link" href="#index-asctime"> ¶</a></span></dt>
<dd><p>Convert a time structure to a string using the following
format: <code class="code">"ddd mmm mm HH:MM:SS yyyy\n"</code>.
</p>
<p>For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">asctime (localtime (time ()))
⇒ "Mon Feb 17 01:15:06 1997\n"
</pre></div></div>
<p>This is equivalent to <code class="code">ctime (time ())</code>.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFctime">ctime</a>, <a class="ref" href="#XREFlocaltime">localtime</a>, <a class="ref" href="#XREFtime">time</a>.
</p></dd></dl>
<a class="anchor" id="XREFstrftime"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-strftime"><span><code class="def-type"><var class="var">str</var> =</code> <strong class="def-name">strftime</strong> <code class="def-code-arguments">(<var class="var">fmt</var>, <var class="var">tm_struct</var>)</code><a class="copiable-link" href="#index-strftime"> ¶</a></span></dt>
<dd><p>Format the time structure <var class="var">tm_struct</var> in a flexible way using the format
string <var class="var">fmt</var> that contains ‘<samp class="samp">%</samp>’ substitutions similar to those in
<code class="code">printf</code>.
</p>
<p>Except where noted, substituted fields have a fixed size; numeric fields are
padded if necessary. Padding is with zeros by default; for fields that
display a single number, padding can be changed or inhibited by following
the ‘<samp class="samp">%</samp>’ with one of the modifiers described below. Unknown field
specifiers are copied as normal characters. All other characters are copied
to the output without change. For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">strftime ("%r (%Z) %A %e %B %Y", localtime (time ()))
⇒ "01:15:06 AM (CST) Monday 17 February 1997"
</pre></div></div>
<p>Octave’s <code class="code">strftime</code> function supports a superset of the ANSI C field
specifiers.
</p>
<p>Literal character fields:
</p>
<dl class="table">
<dt><code class="code">%%</code></dt>
<dd><p>% character.
</p>
</dd>
<dt><code class="code">%n</code></dt>
<dd><p>Newline character.
</p>
</dd>
<dt><code class="code">%t</code></dt>
<dd><p>Tab character.
</p></dd>
</dl>
<p>Numeric modifiers (a nonstandard extension):
</p>
<dl class="table">
<dt><code class="code">- (dash)</code></dt>
<dd><p>Do not pad the field.
</p>
</dd>
<dt><code class="code">_ (underscore)</code></dt>
<dd><p>Pad the field with spaces.
</p></dd>
</dl>
<p>Time fields:
</p>
<dl class="table">
<dt><code class="code">%H</code></dt>
<dd><p>Hour (00-23).
</p>
</dd>
<dt><code class="code">%I</code></dt>
<dd><p>Hour (01-12).
</p>
</dd>
<dt><code class="code">%k</code></dt>
<dd><p>Hour (0-23).
</p>
</dd>
<dt><code class="code">%l</code></dt>
<dd><p>Hour (1-12).
</p>
</dd>
<dt><code class="code">%M</code></dt>
<dd><p>Minute (00-59).
</p>
</dd>
<dt><code class="code">%p</code></dt>
<dd><p>Locale’s AM or PM.
</p>
</dd>
<dt><code class="code">%r</code></dt>
<dd><p>Time, 12-hour (hh:mm:ss [AP]M).
</p>
</dd>
<dt><code class="code">%R</code></dt>
<dd><p>Time, 24-hour (hh:mm).
</p>
</dd>
<dt><code class="code">%s</code></dt>
<dd><p>Time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension).
</p>
</dd>
<dt><code class="code">%S</code></dt>
<dd><p>Second (00-61).
</p>
</dd>
<dt><code class="code">%T</code></dt>
<dd><p>Time, 24-hour (hh:mm:ss).
</p>
</dd>
<dt><code class="code">%X</code></dt>
<dd><p>Locale’s time representation (%H:%M:%S).
</p>
</dd>
<dt><code class="code">%z</code></dt>
<dd><p>Offset from UTC (±hhmm), or nothing if no time zone is
determinable.
</p>
</dd>
<dt><code class="code">%Z</code></dt>
<dd><p>Time zone (EDT), or nothing if no time zone is determinable.
</p></dd>
</dl>
<p>Date fields:
</p>
<dl class="table">
<dt><code class="code">%a</code></dt>
<dd><p>Locale’s abbreviated weekday name (Sun-Sat).
</p>
</dd>
<dt><code class="code">%A</code></dt>
<dd><p>Locale’s full weekday name, variable length (Sunday-Saturday).
</p>
</dd>
<dt><code class="code">%b</code></dt>
<dd><p>Locale’s abbreviated month name (Jan-Dec).
</p>
</dd>
<dt><code class="code">%B</code></dt>
<dd><p>Locale’s full month name, variable length (January-December).
</p>
</dd>
<dt><code class="code">%c</code></dt>
<dd><p>Locale’s date and time (Sat Nov 04 12:02:33 EST 1989).
</p>
</dd>
<dt><code class="code">%C</code></dt>
<dd><p>Century (00-99).
</p>
</dd>
<dt><code class="code">%d</code></dt>
<dd><p>Day of month (01-31).
</p>
</dd>
<dt><code class="code">%e</code></dt>
<dd><p>Day of month ( 1-31).
</p>
</dd>
<dt><code class="code">%D</code></dt>
<dd><p>Date (mm/dd/yy).
</p>
</dd>
<dt><code class="code">%h</code></dt>
<dd><p>Same as %b.
</p>
</dd>
<dt><code class="code">%j</code></dt>
<dd><p>Day of year (001-366).
</p>
</dd>
<dt><code class="code">%m</code></dt>
<dd><p>Month (01-12).
</p>
</dd>
<dt><code class="code">%U</code></dt>
<dd><p>Week number of year with Sunday as first day of week (00-53).
</p>
</dd>
<dt><code class="code">%w</code></dt>
<dd><p>Day of week (0-6).
</p>
</dd>
<dt><code class="code">%W</code></dt>
<dd><p>Week number of year with Monday as first day of week (00-53).
</p>
</dd>
<dt><code class="code">%x</code></dt>
<dd><p>Locale’s date representation (mm/dd/yy).
</p>
</dd>
<dt><code class="code">%y</code></dt>
<dd><p>Last two digits of year (00-99).
</p>
</dd>
<dt><code class="code">%Y</code></dt>
<dd><p>Year (1970-).
</p></dd>
</dl>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFstrptime">strptime</a>, <a class="ref" href="#XREFlocaltime">localtime</a>, <a class="ref" href="#XREFgmtime">gmtime</a>, <a class="ref" href="#XREFmktime">mktime</a>, <a class="ref" href="#XREFtime">time</a>, <a class="ref" href="#XREFnow">now</a>, <a class="ref" href="#XREFdate">date</a>, <a class="ref" href="#XREFclock">clock</a>, <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatestr">datestr</a>, <a class="ref" href="#XREFdatevec">datevec</a>, <a class="ref" href="#XREFcalendar">calendar</a>, <a class="ref" href="#XREFweekday">weekday</a>.
</p></dd></dl>
<a class="anchor" id="XREFstrptime"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-strptime"><span><code class="def-type">[<var class="var">tm_struct</var>, <var class="var">nchars</var>] =</code> <strong class="def-name">strptime</strong> <code class="def-code-arguments">(<var class="var">str</var>, <var class="var">fmt</var>)</code><a class="copiable-link" href="#index-strptime"> ¶</a></span></dt>
<dd><p>Convert the string <var class="var">str</var> to the time structure <var class="var">tm_struct</var> under
the control of the format string <var class="var">fmt</var>.
</p>
<p>If <var class="var">fmt</var> fails to match, <var class="var">nchars</var> is 0; otherwise, it is set to the
position of last matched character plus 1. Always check for this unless
you’re absolutely sure the date string will be parsed correctly.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFstrftime">strftime</a>, <a class="ref" href="#XREFlocaltime">localtime</a>, <a class="ref" href="#XREFgmtime">gmtime</a>, <a class="ref" href="#XREFmktime">mktime</a>, <a class="ref" href="#XREFtime">time</a>, <a class="ref" href="#XREFnow">now</a>, <a class="ref" href="#XREFdate">date</a>, <a class="ref" href="#XREFclock">clock</a>, <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatestr">datestr</a>, <a class="ref" href="#XREFdatevec">datevec</a>, <a class="ref" href="#XREFcalendar">calendar</a>, <a class="ref" href="#XREFweekday">weekday</a>.
</p></dd></dl>
<p>Most of the remaining functions described in this section are not
patterned after the standard C library. Some are available for
compatibility with <small class="sc">MATLAB</small> and others are provided because they are
useful.
</p>
<a class="anchor" id="XREFclock"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-clock"><span><code class="def-type"><var class="var">datevec</var> =</code> <strong class="def-name">clock</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-clock"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-clock-1"><span><code class="def-type">[<var class="var">datevec</var>, <var class="var">isdst</var>] =</code> <strong class="def-name">clock</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-clock-1"> ¶</a></span></dt>
<dd><p>Return the current local date and time as a date vector.
</p>
<p>The date vector contains the following fields: current year, month (1-12),
day (1-31), hour (0-23), minute (0-59), and second (0-61). The seconds
field has a fractional part after the decimal point for extended accuracy.
</p>
<p>The optional second output <var class="var">isdst</var> is true if Daylight Savings Time
(DST) is in effect for the system’s time zone.
</p>
<p>For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">fix (clock ())
⇒ 1993 8 20 4 56 1
</pre></div></div>
<p><code class="code">clock</code> is more accurate on systems that have the <code class="code">gettimeofday</code>
function.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFnow">now</a>, <a class="ref" href="#XREFdate">date</a>, <a class="ref" href="#XREFdatevec">datevec</a>.
</p></dd></dl>
<a class="anchor" id="XREFdate"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-date"><span><code class="def-type"><var class="var">str</var> =</code> <strong class="def-name">date</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-date"> ¶</a></span></dt>
<dd><p>Return the current date as a character string in the form DD-MMM-YYYY.
</p>
<p>For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">date ()
⇒ 20-Aug-1993
</pre></div></div>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFnow">now</a>, <a class="ref" href="#XREFclock">clock</a>, <a class="ref" href="#XREFdatestr">datestr</a>, <a class="ref" href="#XREFlocaltime">localtime</a>.
</p></dd></dl>
<a class="anchor" id="XREFetime"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-etime"><span><code class="def-type"><var class="var">secs</var> =</code> <strong class="def-name">etime</strong> <code class="def-code-arguments">(<var class="var">t2</var>, <var class="var">t1</var>)</code><a class="copiable-link" href="#index-etime"> ¶</a></span></dt>
<dd><p>Return the difference in seconds between two time values returned from
<code class="code">clock</code> (<em class="math"><var class="var">t2</var> - <var class="var">t1</var></em>).
</p>
<p>For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">t0 = clock ();
# many computations later...
elapsed_time = etime (clock (), t0);
</pre></div></div>
<p>will set the variable <code class="code">elapsed_time</code> to the number of seconds since the
variable <code class="code">t0</code> was set.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFtic">tic</a>, <a class="ref" href="#XREFtoc">toc</a>, <a class="ref" href="#XREFclock">clock</a>, <a class="ref" href="#XREFcputime">cputime</a>, <a class="ref" href="#XREFaddtodate">addtodate</a>.
</p></dd></dl>
<a class="anchor" id="XREFcputime"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-cputime"><span><code class="def-type">[<var class="var">total</var>, <var class="var">user</var>, <var class="var">system</var>] =</code> <strong class="def-name">cputime</strong> <code class="def-code-arguments">();</code><a class="copiable-link" href="#index-cputime"> ¶</a></span></dt>
<dd><p>Return the CPU time used by your Octave session.
</p>
<p>The first output is the total time spent executing your process and is equal
to the sum of second and third outputs, which are the number of CPU seconds
spent executing in user mode and the number of CPU seconds spent executing
in system mode, respectively.
</p>
<p>If your system does not have a way to report CPU time usage, <code class="code">cputime</code>
returns 0 for each of its output values.
</p>
<p>Note that because Octave used some CPU time to start, it is reasonable
to check to see if <code class="code">cputime</code> works by checking to see if the total
CPU time used is nonzero.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFtic">tic</a>, <a class="ref" href="#XREFtoc">toc</a>.
</p></dd></dl>
<a class="anchor" id="XREFis_005fleap_005fyear"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-is_005fleap_005fyear"><span><code class="def-type"><var class="var">tf</var> =</code> <strong class="def-name">is_leap_year</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-is_005fleap_005fyear"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-is_005fleap_005fyear-1"><span><code class="def-type"><var class="var">tf</var> =</code> <strong class="def-name">is_leap_year</strong> <code class="def-code-arguments">(<var class="var">year</var>)</code><a class="copiable-link" href="#index-is_005fleap_005fyear-1"> ¶</a></span></dt>
<dd><p>Return true if <var class="var">year</var> is a leap year and false otherwise.
</p>
<p>If no year is specified, <code class="code">is_leap_year</code> uses the current year.
</p>
<p>For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">is_leap_year (2000)
⇒ 1
</pre></div></div>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFweekday">weekday</a>, <a class="ref" href="#XREFeomday">eomday</a>, <a class="ref" href="#XREFcalendar">calendar</a>.
</p></dd></dl>
<a class="anchor" id="XREFtic"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-tic"><span><strong class="def-name">tic</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-tic"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-tic-1"><span><code class="def-type"><var class="var">id</var> =</code> <strong class="def-name">tic</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-tic-1"> ¶</a></span></dt>
<dd><p>Initialize a wall-clock timer.
</p>
<p>Calling <code class="code">tic</code> without an output argument resets the internal timer.
Subsequent calls to <code class="code">toc</code> return the number of seconds since the timer was
set.
</p>
<p>If called with one output argument, <code class="code">tic</code> creates a new timer instance and
returns a timer identifier <var class="var">id</var>. The <var class="var">id</var> is a scalar of type
<code class="code">uint64</code> that may be passed to <code class="code">toc</code> to check elapsed time on this
timer, rather than the default internal timer.
</p>
<p>Example 1 : benchmarking code with internal timer
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">tic;
# many computations later...
elapsed_time = toc;
</pre></div></div>
<p>Example 2 : mixed timer id and internal timer
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">tic;
pause (1);
toc
⇒ Elapsed time is 1.0089 seconds.
id = tic;
pause (2);
toc (id)
⇒ Elapsed time is 2.01142 seconds.
toc
Elapsed time is 3.02308 seconds.
</pre></div></div>
<p>Calling <code class="code">tic</code> and <code class="code">toc</code> in this way allows nested timing calls.
</p>
<p>If you are more interested in the CPU time that your process used, you should
use the <code class="code">cputime</code> function instead. The <code class="code">tic</code> and <code class="code">toc</code>
functions report the actual wall clock time that elapsed between the calls.
This may include time spent processing other jobs or doing nothing at all.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFtoc">toc</a>, <a class="ref" href="#XREFcputime">cputime</a>.
</p></dd></dl>
<a class="anchor" id="XREFtoc"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-toc"><span><strong class="def-name">toc</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-toc"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-toc-1"><span><strong class="def-name">toc</strong> <code class="def-code-arguments">(<var class="var">id</var>)</code><a class="copiable-link" href="#index-toc-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-toc-2"><span><code class="def-type"><var class="var">elapsed_time</var> =</code> <strong class="def-name">toc</strong> <code class="def-code-arguments">(…)</code><a class="copiable-link" href="#index-toc-2"> ¶</a></span></dt>
<dd><p>Measure elapsed time on a wall-clock timer.
</p>
<p>With no arguments, return the number of seconds elapsed on the internal timer
since the last call to <code class="code">tic</code>.
</p>
<p>When given the identifier <var class="var">id</var> of a specific timer, return the number of
seconds elapsed since the timer <var class="var">id</var> was initialized.
</p>
<p>See <a class="xref" href="#XREFtic"><code class="code">tic</code></a>, for examples of the use of <code class="code">tic</code>/<code class="code">toc</code>.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFtic">tic</a>, <a class="ref" href="#XREFcputime">cputime</a>.
</p></dd></dl>
<a class="anchor" id="XREFpause"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-pause-2"><span><strong class="def-name">pause</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-pause-2"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-pause-3"><span><strong class="def-name">pause</strong> <code class="def-code-arguments">(<var class="var">n</var>)</code><a class="copiable-link" href="#index-pause-3"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-pause-4"><span><code class="def-type"><var class="var">old_state</var> =</code> <strong class="def-name">pause</strong> <code class="def-code-arguments">("on")</code><a class="copiable-link" href="#index-pause-4"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-pause-5"><span><code class="def-type"><var class="var">old_state</var> =</code> <strong class="def-name">pause</strong> <code class="def-code-arguments">("off")</code><a class="copiable-link" href="#index-pause-5"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-pause-6"><span><code class="def-type"><var class="var">old_state</var> =</code> <strong class="def-name">pause</strong> <code class="def-code-arguments">("query")</code><a class="copiable-link" href="#index-pause-6"> ¶</a></span></dt>
<dd><p>Suspend the execution of the program or change the state of the pause function.
</p>
<p>If invoked without an input arguments then the program is suspended until a
character is typed. If argument <var class="var">n</var> is a positive real value, it indicates
the number of seconds the program shall be suspended, for example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">tic; pause (0.05); toc
-| Elapsed time is 0.05039 seconds.
</pre></div></div>
<p>The following example prints a message and then waits 5 seconds before clearing
the screen.
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">disp ("wait please...");
pause (5);
clc;
</pre></div></div>
<p>If invoked with a string argument <code class="code">"on"</code>, <code class="code">"off"</code>, or
<code class="code">"query"</code>, the state of the pause function is changed or queried. When
the state is <code class="code">"off"</code>, the pause function returns immediately. The
optional return value contains the previous state of the pause function. In
the following example pause is disabled locally:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">old_state = pause ("off");
tic; pause (0.05); toc
-| Elapsed time is 3.00407e-05 seconds.
pause (old_state);
</pre></div></div>
<p>While the program is suspended Octave still handles figures painting and
graphics callbacks execution.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Terminal-Input.html#XREFkbhit">kbhit</a>.
</p></dd></dl>
<a class="anchor" id="XREFdatenum"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-datenum"><span><code class="def-type"><var class="var">days</var> =</code> <strong class="def-name">datenum</strong> <code class="def-code-arguments">(<var class="var">datevec</var>)</code><a class="copiable-link" href="#index-datenum"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datenum-1"><span><code class="def-type"><var class="var">days</var> =</code> <strong class="def-name">datenum</strong> <code class="def-code-arguments">(<var class="var">year</var>, <var class="var">month</var>, <var class="var">day</var>)</code><a class="copiable-link" href="#index-datenum-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datenum-2"><span><code class="def-type"><var class="var">days</var> =</code> <strong class="def-name">datenum</strong> <code class="def-code-arguments">(<var class="var">year</var>, <var class="var">month</var>, <var class="var">day</var>, <var class="var">hour</var>)</code><a class="copiable-link" href="#index-datenum-2"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datenum-3"><span><code class="def-type"><var class="var">days</var> =</code> <strong class="def-name">datenum</strong> <code class="def-code-arguments">(<var class="var">year</var>, <var class="var">month</var>, <var class="var">day</var>, <var class="var">hour</var>, <var class="var">minute</var>)</code><a class="copiable-link" href="#index-datenum-3"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datenum-4"><span><code class="def-type"><var class="var">days</var> =</code> <strong class="def-name">datenum</strong> <code class="def-code-arguments">(<var class="var">year</var>, <var class="var">month</var>, <var class="var">day</var>, <var class="var">hour</var>, <var class="var">minute</var>, <var class="var">second</var>)</code><a class="copiable-link" href="#index-datenum-4"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datenum-5"><span><code class="def-type"><var class="var">days</var> =</code> <strong class="def-name">datenum</strong> <code class="def-code-arguments">("datestr")</code><a class="copiable-link" href="#index-datenum-5"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datenum-6"><span><code class="def-type"><var class="var">days</var> =</code> <strong class="def-name">datenum</strong> <code class="def-code-arguments">("datestr", <var class="var">f</var>)</code><a class="copiable-link" href="#index-datenum-6"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datenum-7"><span><code class="def-type"><var class="var">days</var> =</code> <strong class="def-name">datenum</strong> <code class="def-code-arguments">("datestr", <var class="var">p</var>)</code><a class="copiable-link" href="#index-datenum-7"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datenum-8"><span><code class="def-type">[<var class="var">days</var>, <var class="var">secs</var>] =</code> <strong class="def-name">datenum</strong> <code class="def-code-arguments">(…)</code><a class="copiable-link" href="#index-datenum-8"> ¶</a></span></dt>
<dd><p>Return the date/time input as a serial day number, with Jan 1, 0000
defined as day 1.
</p>
<p>The integer part, <code class="code">floor (<var class="var">days</var>)</code> counts the number of
complete days in the date input.
</p>
<p>The fractional part, <code class="code">rem (<var class="var">days</var>, 1)</code> corresponds to the time
on the given day.
</p>
<p>The input may be a date vector (see <a class="pxref" href="#XREFdatevec"><code class="code">datevec</code></a>),
date string (see <a class="pxref" href="#XREFdatestr"><code class="code">datestr</code></a>), or directly specified
as input.
</p>
<p>When processing input datestrings, <var class="var">f</var> is the format string used to
interpret date strings (see <a class="pxref" href="#XREFdatestr"><code class="code">datestr</code></a>). If no
format <var class="var">f</var> is specified, then a relatively slow search is performed
through various formats. It is always preferable to specify the format
string <var class="var">f</var> if it is known. Formats which do not specify a particular
time component will have the value set to zero. Formats which do not
specify a date will default to January 1st of the current year.
</p>
<p>When passing separate <var class="var">year</var>, <var class="var">month</var>, <var class="var">day</var>, etc. arguments,
each may be a scalar or nonscalar array. Nonscalar inputs must all be of
the same size. Scalar inputs will be expanded to be the size of the
nonscalar inputs.
</p>
<p><var class="var">p</var> is the year at the start of the century to which two-digit years
will be referenced. If not specified, it defaults to the current year
minus 50.
</p>
<p>The optional output <var class="var">secs</var> holds the time on the specified day with
greater precision than <var class="var">days</var>.
</p>
<p>Notes:
</p>
<ul class="itemize mark-bullet">
<li>Years can be negative and/or fractional.
</li><li>Months below 1 are considered to be January.
</li><li>Days of the month start at 1.
</li><li>Days beyond the end of the month go into subsequent months.
</li><li>Days before the beginning of the month go to the previous month.
</li><li>Days can be fractional.
</li></ul>
<p>Examples:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">Convert from datestrs:
d = datenum ("1966-06-14")
⇒ d = 718232
</pre></div><pre class="example-preformatted">
</pre><div class="group"><pre class="example-preformatted">d = datenum ({"1966-06-14", "1966-06-15", "1966-06-16"})
⇒ d =
718232
718233
718234
</pre></div><pre class="example-preformatted">
</pre><div class="group"><pre class="example-preformatted">Convert from datevec:
d = datenum ([1966 06 14])
⇒ d = 718232
</pre></div><pre class="example-preformatted">
</pre><div class="group"><pre class="example-preformatted">d = datenum ([1966 06 14 23 59 59])
⇒ d = 718232.9999884259
</pre></div><pre class="example-preformatted">
</pre><div class="group"><pre class="example-preformatted">Specify date components separately:
d = datenum (1966, 6, 14)
⇒ d = 718232
</pre></div><pre class="example-preformatted">
</pre><div class="group"><pre class="example-preformatted">d = datenum (1966, magic(3), 1)
⇒ d =
718280 718068 718219
718127 718188 718249
718158 718311 718099
</pre></div></div>
<p><strong class="strong">Caution:</strong> datenums represent a specific time for the Earth as a
whole. They do not take in to account time zones (shifts in time based
on location), nor seasonal changes due to Daylight Savings Time (shifts in
time based on local regulation). Be aware that it is possible to create
datenums that, when interpreted by a function which accounts for time zone
and DST shifts such as <code class="code">datestr</code>, are nonexistent or ambiguous.
</p>
<p><strong class="strong">Caution:</strong> this function does not attempt to handle Julian calendars
so dates before October 15, 1582 are wrong by as much as eleven days. Also,
be aware that only Roman Catholic countries adopted the calendar in 1582.
It took until 1924 for it to be adopted everywhere. See the Wikipedia entry
on the Gregorian calendar for more details.
</p>
<p><strong class="strong">Warning:</strong> leap seconds are ignored. A table of leap seconds is
available on the Wikipedia entry for leap seconds.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFdatestr">datestr</a>, <a class="ref" href="#XREFdatevec">datevec</a>, <a class="ref" href="#XREFnow">now</a>, <a class="ref" href="#XREFclock">clock</a>, <a class="ref" href="#XREFdate">date</a>.
</p></dd></dl>
<a class="anchor" id="XREFdatestr"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-datestr"><span><code class="def-type"><var class="var">str</var> =</code> <strong class="def-name">datestr</strong> <code class="def-code-arguments">(<var class="var">date</var>)</code><a class="copiable-link" href="#index-datestr"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datestr-1"><span><code class="def-type"><var class="var">str</var> =</code> <strong class="def-name">datestr</strong> <code class="def-code-arguments">(<var class="var">date</var>, <var class="var">f</var>)</code><a class="copiable-link" href="#index-datestr-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datestr-2"><span><code class="def-type"><var class="var">str</var> =</code> <strong class="def-name">datestr</strong> <code class="def-code-arguments">(<var class="var">date</var>, <var class="var">f</var>, <var class="var">p</var>)</code><a class="copiable-link" href="#index-datestr-2"> ¶</a></span></dt>
<dd><p>Format the given date/time according to the format <var class="var">f</var> and return
the result in <var class="var">str</var>.
</p>
<p><var class="var">date</var> is a serial date number (see <a class="pxref" href="#XREFdatenum"><code class="code">datenum</code></a>), a
date vector (see <a class="pxref" href="#XREFdatevec"><code class="code">datevec</code></a>), or a string or cell array
of strings. In the latter case, it is passed to <code class="code">datevec</code> to guess the
input date format.
</p>
<p><var class="var">f</var> can be an integer which corresponds to one of the codes in the table
below, or a date format string.
</p>
<p><var class="var">p</var> is the year at the start of the century in which two-digit years are
to be interpreted in. If not specified, it defaults to the current year
minus 50.
</p>
<p>For example, the date 730736.65149 (2000-09-07 15:38:09.0934) would be
formatted as follows:
</p>
<table class="multitable">
<thead><tr><th width="10%">Code</th><th width="45%">Format</th><th width="35%">Example</th></tr></thead>
<tbody><tr><td width="10%">0</td><td width="45%">dd-mmm-yyyy HH:MM:SS</td><td width="35%">07-Sep-2000 15:38:09</td></tr>
<tr><td width="10%">1</td><td width="45%">dd-mmm-yyyy</td><td width="35%">07-Sep-2000</td></tr>
<tr><td width="10%">2</td><td width="45%">mm/dd/yy</td><td width="35%">09/07/00</td></tr>
<tr><td width="10%">3</td><td width="45%">mmm</td><td width="35%">Sep</td></tr>
<tr><td width="10%">4</td><td width="45%">m</td><td width="35%">S</td></tr>
<tr><td width="10%">5</td><td width="45%">mm</td><td width="35%">09</td></tr>
<tr><td width="10%">6</td><td width="45%">mm/dd</td><td width="35%">09/07</td></tr>
<tr><td width="10%">7</td><td width="45%">dd</td><td width="35%">07</td></tr>
<tr><td width="10%">8</td><td width="45%">ddd</td><td width="35%">Thu</td></tr>
<tr><td width="10%">9</td><td width="45%">d</td><td width="35%">T</td></tr>
<tr><td width="10%">10</td><td width="45%">yyyy</td><td width="35%">2000</td></tr>
<tr><td width="10%">11</td><td width="45%">yy</td><td width="35%">00</td></tr>
<tr><td width="10%">12</td><td width="45%">mmmyy</td><td width="35%">Sep00</td></tr>
<tr><td width="10%">13</td><td width="45%">HH:MM:SS</td><td width="35%">15:38:09</td></tr>
<tr><td width="10%">14</td><td width="45%">HH:MM:SS PM</td><td width="35%">3:38:09 PM</td></tr>
<tr><td width="10%">15</td><td width="45%">HH:MM</td><td width="35%">15:38</td></tr>
<tr><td width="10%">16</td><td width="45%">HH:MM PM</td><td width="35%">3:38 PM</td></tr>
<tr><td width="10%">17</td><td width="45%">QQ-YY</td><td width="35%">Q3-00</td></tr>
<tr><td width="10%">18</td><td width="45%">QQ</td><td width="35%">Q3</td></tr>
<tr><td width="10%">19</td><td width="45%">dd/mm</td><td width="35%">07/09</td></tr>
<tr><td width="10%">20</td><td width="45%">dd/mm/yy</td><td width="35%">07/09/00</td></tr>
<tr><td width="10%">21</td><td width="45%">mmm.dd,yyyy HH:MM:SS</td><td width="35%">Sep.07,2000 15:38:08</td></tr>
<tr><td width="10%">22</td><td width="45%">mmm.dd,yyyy</td><td width="35%">Sep.07,2000</td></tr>
<tr><td width="10%">23</td><td width="45%">mm/dd/yyyy</td><td width="35%">09/07/2000</td></tr>
<tr><td width="10%">24</td><td width="45%">dd/mm/yyyy</td><td width="35%">07/09/2000</td></tr>
<tr><td width="10%">25</td><td width="45%">yy/mm/dd</td><td width="35%">00/09/07</td></tr>
<tr><td width="10%">26</td><td width="45%">yyyy/mm/dd</td><td width="35%">2000/09/07</td></tr>
<tr><td width="10%">27</td><td width="45%">QQ-YYYY</td><td width="35%">Q3-2000</td></tr>
<tr><td width="10%">28</td><td width="45%">mmmyyyy</td><td width="35%">Sep2000</td></tr>
<tr><td width="10%">29</td><td width="45%">yyyy-mm-dd</td><td width="35%">2000-09-07</td></tr>
<tr><td width="10%">30</td><td width="45%">yyyymmddTHHMMSS</td><td width="35%">20000907T153808</td></tr>
<tr><td width="10%">31</td><td width="45%">yyyy-mm-dd HH:MM:SS</td><td width="35%">2000-09-07 15:38:08</td></tr>
</tbody>
</table>
<p>If <var class="var">f</var> is a format string, the following symbols are recognized:
</p>
<table class="multitable">
<thead><tr><th width="10%">Symbol</th><th width="70%">Meaning</th><th width="20%">Example</th></tr></thead>
<tbody><tr><td width="10%">yyyy</td><td width="70%">Full year</td><td width="20%">2005</td></tr>
<tr><td width="10%">yy</td><td width="70%">Two-digit year</td><td width="20%">05</td></tr>
<tr><td width="10%">mmmm</td><td width="70%">Full month name</td><td width="20%">December</td></tr>
<tr><td width="10%">mmm</td><td width="70%">Abbreviated month name</td><td width="20%">Dec</td></tr>
<tr><td width="10%">mm</td><td width="70%">Numeric month number (padded with zeros)</td><td width="20%">01, 08, 12</td></tr>
<tr><td width="10%">m</td><td width="70%">First letter of month name (capitalized)</td><td width="20%">D</td></tr>
<tr><td width="10%">dddd</td><td width="70%">Full weekday name</td><td width="20%">Sunday</td></tr>
<tr><td width="10%">ddd</td><td width="70%">Abbreviated weekday name</td><td width="20%">Sun</td></tr>
<tr><td width="10%">dd</td><td width="70%">Numeric day of month (padded with zeros)</td><td width="20%">11</td></tr>
<tr><td width="10%">d</td><td width="70%">First letter of weekday name (capitalized)</td><td width="20%">S</td></tr>
<tr><td width="10%">HH</td><td width="70%">Hour of day, padded with zeros,</td><td width="20%">09:00</td></tr>
<tr><td width="10%"></td><td width="70%">or padded with spaces if PM is set</td><td width="20%">9:00 AM</td></tr>
<tr><td width="10%">MM</td><td width="70%">Minute of hour (padded with zeros)</td><td width="20%">10:05</td></tr>
<tr><td width="10%">SS</td><td width="70%">Second of minute (padded with zeros)</td><td width="20%">10:05:03</td></tr>
<tr><td width="10%">FFF</td><td width="70%">Milliseconds of second (padded with zeros)</td><td width="20%">10:05:03.012</td></tr>
<tr><td width="10%">AM</td><td width="70%">Use 12-hour time format</td><td width="20%">11:30 AM</td></tr>
<tr><td width="10%">PM</td><td width="70%">Use 12-hour time format</td><td width="20%">11:30 PM</td></tr>
</tbody>
</table>
<p>If <var class="var">f</var> is not specified or is <code class="code">-1</code>, then use 0, 1 or 16, depending
on whether the date portion or the time portion of <var class="var">date</var> is empty.
</p>
<p>If <var class="var">p</var> is not specified, it defaults to the current year minus 50.
</p>
<p>If a matrix or cell array of dates is given, a column vector of date strings
is returned.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatevec">datevec</a>, <a class="ref" href="#XREFdate">date</a>, <a class="ref" href="#XREFnow">now</a>, <a class="ref" href="#XREFclock">clock</a>.
</p></dd></dl>
<a class="anchor" id="XREFdatevec"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-datevec"><span><code class="def-type"><var class="var">v</var> =</code> <strong class="def-name">datevec</strong> <code class="def-code-arguments">(<var class="var">date</var>)</code><a class="copiable-link" href="#index-datevec"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datevec-1"><span><code class="def-type"><var class="var">v</var> =</code> <strong class="def-name">datevec</strong> <code class="def-code-arguments">(<var class="var">date</var>, <var class="var">f</var>)</code><a class="copiable-link" href="#index-datevec-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datevec-2"><span><code class="def-type"><var class="var">v</var> =</code> <strong class="def-name">datevec</strong> <code class="def-code-arguments">(<var class="var">date</var>, <var class="var">p</var>)</code><a class="copiable-link" href="#index-datevec-2"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datevec-3"><span><code class="def-type"><var class="var">v</var> =</code> <strong class="def-name">datevec</strong> <code class="def-code-arguments">(<var class="var">date</var>, <var class="var">f</var>, <var class="var">p</var>)</code><a class="copiable-link" href="#index-datevec-3"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datevec-4"><span><code class="def-type">[<var class="var">y</var>, <var class="var">m</var>, <var class="var">d</var>, <var class="var">h</var>, <var class="var">mi</var>, <var class="var">s</var>] =</code> <strong class="def-name">datevec</strong> <code class="def-code-arguments">(…)</code><a class="copiable-link" href="#index-datevec-4"> ¶</a></span></dt>
<dd><p>Convert a serial date number (see <a class="pxref" href="#XREFdatenum"><code class="code">datenum</code></a>) or date
string (see <a class="pxref" href="#XREFdatestr"><code class="code">datestr</code></a>) into a date vector.
</p>
<p>A date vector is a row vector with six members, representing the year,
month, day, hour, minute, and seconds respectively.
</p>
<p>Date number inputs can be either a scalar or nonscalar array. Date string
inputs can be either a single date string, a two-dimensional character
array of dates with each row being a date string, or a cell string array of
any dimension with each cell element containing a single date string.
</p>
<p><var class="var">v</var> is a two-dimensional array of date vectors, one date vector per
row. For array inputs, ordering of <var class="var">v</var> is based on column major order
of dates in <var class="var">data</var>.
</p>
<p><var class="var">f</var> is the format string used to interpret date strings
(see <a class="pxref" href="#XREFdatestr"><code class="code">datestr</code></a>). If <var class="var">date</var> is a string or a cell
array of strings, but no format is specified, heuristics are used to guess
the input format. These heuristics could lead to matches that differ from
the result a user might expect. Additionally, this involves a relatively
slow search through various formats. It is always preferable to specify
the format string <var class="var">f</var> if it is known. Formats which do not specify a
particular time component will have the value set to zero. Formats which
do not specify a particular date component will default that component to
January 1st of the current year. Trailing characters are ignored for the
purpose of calculating the date vector, even if the characters contain
additional time/date information.
</p>
<p><var class="var">p</var> is the year at the start of the century to which two-digit years
will be referenced. If not specified, it defaults to the current year
minus 50.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatestr">datestr</a>, <a class="ref" href="#XREFclock">clock</a>, <a class="ref" href="#XREFnow">now</a>, <a class="ref" href="#XREFdate">date</a>.
</p></dd></dl>
<a class="anchor" id="XREFaddtodate"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-addtodate"><span><code class="def-type"><var class="var">d</var> =</code> <strong class="def-name">addtodate</strong> <code class="def-code-arguments">(<var class="var">d</var>, <var class="var">q</var>, <var class="var">f</var>)</code><a class="copiable-link" href="#index-addtodate"> ¶</a></span></dt>
<dd><p>Add <var class="var">q</var> amount of time (with units <var class="var">f</var>) to the serial datenum,
<var class="var">d</var>.
</p>
<p><var class="var">f</var> must be one of <code class="code">"year"</code>, <code class="code">"month"</code>, <code class="code">"day"</code>,
<code class="code">"hour"</code>, <code class="code">"minute"</code>, <code class="code">"second"</code>, or
<code class="code">"millisecond"</code>.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatevec">datevec</a>, <a class="ref" href="#XREFetime">etime</a>.
</p></dd></dl>
<a class="anchor" id="XREFcalendar"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-calendar"><span><code class="def-type"><var class="var">c</var> =</code> <strong class="def-name">calendar</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-calendar"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-calendar-1"><span><code class="def-type"><var class="var">c</var> =</code> <strong class="def-name">calendar</strong> <code class="def-code-arguments">(<var class="var">d</var>)</code><a class="copiable-link" href="#index-calendar-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-calendar-2"><span><code class="def-type"><var class="var">c</var> =</code> <strong class="def-name">calendar</strong> <code class="def-code-arguments">(<var class="var">y</var>, <var class="var">m</var>)</code><a class="copiable-link" href="#index-calendar-2"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-calendar-3"><span><strong class="def-name">calendar</strong> <code class="def-code-arguments">(…)</code><a class="copiable-link" href="#index-calendar-3"> ¶</a></span></dt>
<dd><p>Return the current monthly calendar in a 6x7 matrix.
</p>
<p>If <var class="var">d</var> is specified, return the calendar for the month containing the
date <var class="var">d</var>, which must be a serial date number or a date string.
</p>
<p>If <var class="var">y</var> and <var class="var">m</var> are specified, return the calendar for year <var class="var">y</var>
and month <var class="var">m</var>.
</p>
<p>If no output arguments are specified, print the calendar on the screen
instead of returning a matrix.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatestr">datestr</a>.
</p></dd></dl>
<a class="anchor" id="XREFweekday"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-weekday"><span><code class="def-type">[<var class="var">n</var>, <var class="var">s</var>] =</code> <strong class="def-name">weekday</strong> <code class="def-code-arguments">(<var class="var">d</var>)</code><a class="copiable-link" href="#index-weekday"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-weekday-1"><span><code class="def-type">[<var class="var">n</var>, <var class="var">s</var>] =</code> <strong class="def-name">weekday</strong> <code class="def-code-arguments">(<var class="var">d</var>, <var class="var">format</var>)</code><a class="copiable-link" href="#index-weekday-1"> ¶</a></span></dt>
<dd><p>Return the day of the week as a number in <var class="var">n</var> and as a string in
<var class="var">s</var>.
</p>
<p>The days of the week are numbered 1–7 with the first day being Sunday.
</p>
<p><var class="var">d</var> is a serial date number or a date string.
</p>
<p>If the string <var class="var">format</var> is not present or is equal to <code class="code">"short"</code>
then <var class="var">s</var> will contain the abbreviated name of the weekday. If
<var class="var">format</var> is <code class="code">"long"</code> then <var class="var">s</var> will contain the full name.
</p>
<p>Table of return values based on <var class="var">format</var>:
</p>
<table class="multitable">
<thead><tr><th width="6%"><var class="var">n</var></th><th width="13%"><code class="code">"short"</code></th><th width="16%"><code class="code">"long"</code></th></tr></thead>
<tbody><tr><td width="6%">1</td><td width="13%">Sun</td><td width="16%">Sunday</td></tr>
<tr><td width="6%">2</td><td width="13%">Mon</td><td width="16%">Monday</td></tr>
<tr><td width="6%">3</td><td width="13%">Tue</td><td width="16%">Tuesday</td></tr>
<tr><td width="6%">4</td><td width="13%">Wed</td><td width="16%">Wednesday</td></tr>
<tr><td width="6%">5</td><td width="13%">Thu</td><td width="16%">Thursday</td></tr>
<tr><td width="6%">6</td><td width="13%">Fri</td><td width="16%">Friday</td></tr>
<tr><td width="6%">7</td><td width="13%">Sat</td><td width="16%">Saturday</td></tr>
</tbody>
</table>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFeomday">eomday</a>, <a class="ref" href="#XREFis_005fleap_005fyear">is_leap_year</a>, <a class="ref" href="#XREFcalendar">calendar</a>, <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatevec">datevec</a>.
</p></dd></dl>
<a class="anchor" id="XREFeomday"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-eomday"><span><code class="def-type"><var class="var">e</var> =</code> <strong class="def-name">eomday</strong> <code class="def-code-arguments">(<var class="var">y</var>, <var class="var">m</var>)</code><a class="copiable-link" href="#index-eomday"> ¶</a></span></dt>
<dd><p>Return the last day of the month <var class="var">m</var> for the year <var class="var">y</var>.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFweekday">weekday</a>, <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatevec">datevec</a>, <a class="ref" href="#XREFis_005fleap_005fyear">is_leap_year</a>, <a class="ref" href="#XREFcalendar">calendar</a>.
</p></dd></dl>
<a class="anchor" id="XREFdatetick"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-datetick"><span><strong class="def-name">datetick</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-datetick"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datetick-1"><span><strong class="def-name">datetick</strong> <code class="def-code-arguments">(<var class="var">axis_str</var>)</code><a class="copiable-link" href="#index-datetick-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datetick-2"><span><strong class="def-name">datetick</strong> <code class="def-code-arguments">(<var class="var">date_format</var>)</code><a class="copiable-link" href="#index-datetick-2"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datetick-3"><span><strong class="def-name">datetick</strong> <code class="def-code-arguments">(<var class="var">axis_str</var>, <var class="var">date_format</var>)</code><a class="copiable-link" href="#index-datetick-3"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datetick-4"><span><strong class="def-name">datetick</strong> <code class="def-code-arguments">(…, "keeplimits")</code><a class="copiable-link" href="#index-datetick-4"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datetick-5"><span><strong class="def-name">datetick</strong> <code class="def-code-arguments">(…, "keepticks")</code><a class="copiable-link" href="#index-datetick-5"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-datetick-6"><span><strong class="def-name">datetick</strong> <code class="def-code-arguments">(<var class="var">hax</var>, …)</code><a class="copiable-link" href="#index-datetick-6"> ¶</a></span></dt>
<dd><p>Add date-formatted tick labels to an axis.
</p>
<p>The axis to apply the ticks to is determined by <var class="var">axis_str</var> which can
take the values <code class="code">"x"</code>, <code class="code">"y"</code>, or <code class="code">"z"</code>. The default
value is <code class="code">"x"</code>.
</p>
<p>The formatting of the labels is determined by the variable
<var class="var">date_format</var>, which can either be a string or positive integer that
<code class="code">datestr</code> accepts.
</p>
<p>If the first argument <var class="var">hax</var> is an axes handle, then plot into this axes,
rather than the current axes returned by <code class="code">gca</code>.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFdatenum">datenum</a>, <a class="ref" href="#XREFdatestr">datestr</a>.
</p></dd></dl>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Filesystem-Utilities.html">Filesystem Utilities</a>, Up: <a href="System-Utilities.html">System Utilities</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|