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
|
'\" te
.\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
.\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
.\" This notice shall appear on any product containing this material.
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH strptime 3C "27 Aug 2007" "SunOS 5.11" "Standard C Library Functions"
.SH NAME
strptime \- date and time conversion
.SH SYNOPSIS
.LP
.nf
#include <time.h>
\fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR,
\fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR);
.fi
.SS "Non-zeroing Behavior"
.LP
.nf
\fBcc\fR [\fIflag\fR...] \fIfile\fR... \fB-D_STRPTIME_DONTZERO\fR [\fIlibrary\fR...]
#include <time.h>
\fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR,
\fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR);
.fi
.SH DESCRIPTION
.sp
.LP
The \fBstrptime()\fR function converts the character string pointed to by
\fIbuf\fR to values which are stored in the \fBtm\fR structure pointed to by
\fItm\fR, using the format specified by \fIformat\fR.
.sp
.LP
The \fIformat\fR argument is composed of zero or more conversion
specifications. Each conversion specification is composed of a "%" (percent)
character followed by one or two conversion characters which specify the
replacement required. One or more white space characters (as specified by
\fBisspace\fR(3C)) may precede or follow a conversion specification. There must
be white-space or other non-alphanumeric characters between any two conversion
specifications.
.sp
.LP
A non-zeroing version of \fBstrptime()\fR, described below under \fBNon-zeroing
Behavior\fR, is provided if \fB_STRPTIME_DONTZERO\fR is defined.
.SS "Conversion Specifications"
.sp
.LP
The following conversion specifications are supported:
.sp
.ne 2
.mk
.na
\fB\fB%%\fR\fR
.ad
.RS 6n
.rt
Same as \fB%\fR.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%a\fR\fR
.ad
.RS 6n
.rt
Day of week, using the locale's weekday names; either the abbreviated or full
name may be specified.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%A\fR\fR
.ad
.RS 6n
.rt
Same as \fB%a\fR.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%b\fR\fR
.ad
.RS 6n
.rt
Month, using the locale's month names; either the abbreviated or full name may
be specified.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%B\fR\fR
.ad
.RS 6n
.rt
Same as \fB%b\fR.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%c\fR\fR
.ad
.RS 6n
.rt
Locale's appropriate date and time representation.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%C\fR\fR
.ad
.RS 6n
.rt
Century number (the year divided by 100 and truncated to an integer as a
decimal number [1,99]); single digits are preceded by 0. If \fB%C\fR is used
without the \fB%y\fR specifier, \fBstrptime()\fR assumes the year offset is
zero in whichever century is specified. Note the behavior of \fB%C\fR in the
absence of \fB%y\fR is not specified by any of the standards or specifications
described on the \fBstandards\fR(5) manual page, so portable applications
should not depend on it. This behavior may change in a future release.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%d\fR\fR
.ad
.RS 6n
.rt
Day of month [1,31]; leading zero is permitted but not required.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%D\fR\fR
.ad
.RS 6n
.rt
Date as \fB%m\fR/\fB%d\fR/\fB%y\fR.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%e\fR\fR
.ad
.RS 6n
.rt
Same as \fB%d\fR.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%h\fR\fR
.ad
.RS 6n
.rt
Same as \fB%b\fR.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%H\fR\fR
.ad
.RS 6n
.rt
Hour (24-hour clock) [0,23]; leading zero is permitted but not required.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%I\fR\fR
.ad
.RS 6n
.rt
Hour (12-hour clock) [1,12]; leading zero is permitted but not required.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%j\fR\fR
.ad
.RS 6n
.rt
Day number of the year [1,366]; leading zeros are permitted but not required.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%m\fR\fR
.ad
.RS 6n
.rt
Month number [1,12]; leading zero is permitted but not required.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%M\fR\fR
.ad
.RS 6n
.rt
Minute [0-59]; leading zero is permitted but not required.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%n\fR\fR
.ad
.RS 6n
.rt
Any white space.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%p\fR\fR
.ad
.RS 6n
.rt
Locale's equivalent of either a.m. or p.m.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%r\fR\fR
.ad
.RS 6n
.rt
Appropriate time representation in the 12-hour clock format with \fB%p\fR.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%R\fR\fR
.ad
.RS 6n
.rt
Time as \fB%H\fR:\fB%M\fR.
.RE
.SS "SUSv3"
.sp
.ne 2
.mk
.na
\fB\fB%S\fR\fR
.ad
.RS 6n
.rt
Seconds [0,60]; leading zero is permitted but not required. The range of values
is [00,60] rather than [00,59] to allow for the occasional leap second.
.RE
.SS "Default and other standards"
.sp
.ne 2
.mk
.na
\fB\fB%S\fR\fR
.ad
.RS 6n
.rt
Seconds [0,61]; leading zero is permitted but not required. The range of values
is [00,61] rather than [00,59] to allow for the occasional leap second and even
more occasional double leap second.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%t\fR\fR
.ad
.RS 6n
.rt
Any white space.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%T\fR\fR
.ad
.RS 6n
.rt
Time as \fB%H\fR:\fB%M\fR:\fB%S\fR.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%U\fR\fR
.ad
.RS 6n
.rt
Week number of the year as a decimal number [0,53], with Sunday as the first
day of the week; leading zero is permitted but not required.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%w\fR\fR
.ad
.RS 6n
.rt
Weekday as a decimal number [0,6], with 0 representing Sunday.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%W\fR\fR
.ad
.RS 6n
.rt
Week number of the year as a decimal number [0,53], with Monday as the first
day of the week; leading zero is permitted but not required.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%x\fR\fR
.ad
.RS 6n
.rt
Locale's appropriate date representation.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%X\fR\fR
.ad
.RS 6n
.rt
Locale's appropriate time representation.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%y\fR\fR
.ad
.RS 6n
.rt
Year within century. When a century is not otherwise specified, values in the
range 69-99 refer to years in the twentieth century (1969 to 1999 inclusive);
values in the range 00-68 refer to years in the twenty-first century (2000 to
2068 inclusive).
.RE
.sp
.ne 2
.mk
.na
\fB\fB%Y\fR\fR
.ad
.RS 6n
.rt
Year, including the century (for example, 1993).
.RE
.sp
.ne 2
.mk
.na
\fB\fB%Z\fR\fR
.ad
.RS 6n
.rt
Time zone name or no characters if no time zone exists.
.RE
.SS "Modified Conversion Specifications"
.sp
.LP
Some conversion specifications can be modified by the \fBE\fR and \fBO\fR
modifier characters to indicate that an alternate format or specification
should be used rather than the one normally used by the unmodified
specification. If the alternate format or specification does not exist in the
current locale, the behavior will be as if the unmodified conversion
specification were used.
.sp
.ne 2
.mk
.na
\fB\fB%Ec\fR\fR
.ad
.RS 7n
.rt
Locale's alternate appropriate date and time representation.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%EC\fR\fR
.ad
.RS 7n
.rt
Name of the base year (era) in the locale's alternate representation.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%Ex\fR\fR
.ad
.RS 7n
.rt
Locale's alternate date representation.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%EX\fR\fR
.ad
.RS 7n
.rt
Locale's alternate time representation.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%Ey\fR\fR
.ad
.RS 7n
.rt
Offset from \fB%EC\fR (year only) in the locale's alternate representation.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%EY\fR\fR
.ad
.RS 7n
.rt
Full alternate year representation.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%Od\fR\fR
.ad
.RS 7n
.rt
Day of the month using the locale's alternate numeric symbols.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%Oe\fR\fR
.ad
.RS 7n
.rt
Same as \fB%Od\fR.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%OH\fR\fR
.ad
.RS 7n
.rt
Hour (24-hour clock) using the locale's alternate numeric symbols.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%OI\fR\fR
.ad
.RS 7n
.rt
Hour (12-hour clock) using the locale's alternate numeric symbols.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%Om\fR\fR
.ad
.RS 7n
.rt
Month using the locale's alternate numeric symbols.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%OM\fR\fR
.ad
.RS 7n
.rt
Minutes using the locale's alternate numeric symbols.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%OS\fR\fR
.ad
.RS 7n
.rt
Seconds using the locale's alternate numeric symbols.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%OU\fR\fR
.ad
.RS 7n
.rt
Week number of the year (Sunday as the first day of the week) using the
locale's alternate numeric symbols.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%Ow\fR\fR
.ad
.RS 7n
.rt
Number of the weekday (Sunday=0) using the locale's alternate numeric symbols.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%OW\fR\fR
.ad
.RS 7n
.rt
Week number of the year (Monday as the first day of the week) using the
locale's alternate numeric symbols.
.RE
.sp
.ne 2
.mk
.na
\fB\fB%Oy\fR\fR
.ad
.RS 7n
.rt
Year (offset from \fB%C\fR) in the locale's alternate representation and using
the locale's alternate numeric symbols.
.RE
.SS "General Specifications"
.sp
.LP
A conversion specification that is an ordinary character is executed by
scanning the next character from the buffer. If the character scanned from the
buffer differs from the one comprising the specification, the specification
fails, and the differing and subsequent characters remain unscanned.
.sp
.LP
A series of specifications composed of \fB%n\fR, \fB%t\fR, white-space
characters or any combination is executed by scanning up to the first character
that is not white space (which remains unscanned), or until no more characters
can be scanned. White space is defined by \fBisspace\fR(3C).
.sp
.LP
Any other conversion specification is executed by scanning characters until a
character matching the next specification is scanned, or until no more
characters can be scanned. These characters, except the one matching the next
specification, are then compared to the locale values associated with the
conversion specifier. If a match is found, values for the appropriate
\fItm\fR structure members are set to values corresponding to the locale
information. If no match is found, \fBstrptime()\fR fails and no more
characters are scanned.
.sp
.LP
The month names, weekday names, era names, and alternate numeric symbols can
consist of any combination of upper and lower case letters. The user can
request that the input date or time specification be in a specific language by
setting the \fBLC_TIME\fR category using \fBsetlocale\fR(3C).
.SS "Non-zeroing Behavior"
.sp
.LP
In addition to the behavior described above by various standards, the Solaris
implementation of \fBstrptime()\fR provides the following extensions. These may
change at any time in the future. Portable applications should not depend on
these extended features:
.RS +4
.TP
.ie t \(bu
.el o
If \fB_STRPTIME_DONTZERO\fR is not defined, the \fBtm struct\fR is zeroed on
entry and \fBstrptime()\fR updates the fields of the \fBtm struct\fR associated
with the specifiers in the format string.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fB_STRPTIME_DONTZERO\fR is defined, \fBstrptime()\fR does not zero the
\fBtm struct\fR on entry. Additionally, for some specifiers, \fBstrptime()\fR
will use some values in the input \fBtm struct\fR to recalculate the date and
re-assign the appropriate members of the \fBtm struct\fR.
.RE
.sp
.LP
The following describes extended features regardless of whether
\fB_STRPTIME_DONTZERO\fR is defined or not defined:
.RS +4
.TP
.ie t \(bu
.el o
If \fB%j\fR is specified, \fBtm_yday\fR is set; if year is given, and if month
and day are not given, \fBstrptime()\fR calculates and sets \fBtm_mon\fR,
\fBtm_mday\fR, and \fBtm_year\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fB%U\fR or \fB%W\fR is specified and if weekday and year are given and
month and day of month are not given, \fBstrptime()\fR calculates and sets
\fBtm_mon\fR, \fBtm_mday\fR, \fBtm_wday\fR, and \fBtm_year\fR.
.RE
.sp
.LP
The following describes extended features when \fB_STRPTIME_DONTZERO\fR is not
defined:
.RS +4
.TP
.ie t \(bu
.el o
If \fB%C\fR is specified and \fB%y\fR is not specified, \fBstrptime()\fRassumes
0 as the year offset, then calculates the year, and assigns \fBtm_year\fR.
.RE
.sp
.LP
The following describes extended features when \fB_STRPTIME_DONTZERO\fR is
defined:
.RS +4
.TP
.ie t \(bu
.el o
If \fB%C\fR is specified and \fB%y\fR is not specified, \fBstrptime()\fR
assumes the year offset of the year value of the \fBtm_year\fR member of the
input \fBtm struct\fR, then calculates the year and assigns \fBtm_year\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fB%j\fR is specified and neither \fB%y\fR, \fB%Y\fR, nor \fB%C\fR are
specified, and neither month nor day of month are specified, \fBstrptime()\fR
assumes the year value given by the value of the \fBtm_year\fR field of the
input \fBtm struct\fR. Then, in addition to setting \fBtm_yday\fR,
\fBstrptime()\fR uses day-of-year and year values to calculate the month and
day-of-month, and assigns \fBtm_month\fR and \fBtm_mday\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fB%U\fR or \fB%W\fR is specified, and if weekday and/or year are not given,
and month and day of month are not given, \fBstrptime()\fR will assume the
weekday value and/or the year value as the value of the \fBtm_wday\fR field
and/or \fBtm_year\fR field of the input \fBtm struct\fR. Then,
\fBstrptime()\fR will calculate the month and day-of-month and assign
\fBtm_month\fR, \fBtm_mday\fR, and/or \fBtm_year\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fB%p\fR is specified and if hour is not specified, \fBstrptime()\fR will
reference, and if needed, update the \fBtm_hour\fR member. If the \fBam_pm\fR
input is p.m. and the input \fBtm_hour\fR value is between 0 - 11,
\fBstrptime()\fR will add 12 hours and update \fBtm_hour\fR. If the
\fBam_pm\fR input is a.m. and input \fBtm_hour\fR value is between 12 - 23,
\fBstrptime()\fR will subtract 12 hours and update \fBtm_hour\fR.
.RE
.SH RETURN VALUES
.sp
.LP
Upon successful completion, \fBstrptime()\fR returns a pointer to the character
following the last character parsed. Otherwise, a null pointer is returned.
.SH USAGE
.sp
.LP
Several "same as" formats, and the special processing of white-space characters
are provided in order to ease the use of identical \fIformat\fR strings for
\fBstrftime\fR(3C) and \fBstrptime()\fR.
.sp
.LP
The \fBstrptime()\fR function tries to calculate \fBtm_year\fR, \fBtm_mon\fR,
and \fBtm_mday\fR when given incomplete input. This allows the \fBstruct tm\fR
created by \fBstrptime()\fR to be passed to \fBmktime\fR(3C) to produce a
\fBtime_t\fR value for dates and times that are representable by a
\fBtime_t\fR. As an example, since \fBmktime()\fR ignores \fBtm_yday\fR,
\fBstrptime()\fR calculates \fBtm_mon\fR and \fBtm_mday\fR as well as filling
in \fBtm_yday\fR when \fB%j\fR is specified without otherwise specifying a
month and day within month.
.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
.sp
.TS
tab() box;
cw(2.75i) |cw(2.75i)
lw(2.75i) |lw(2.75i)
.
ATTRIBUTE TYPEATTRIBUTE VALUE
_
CSIEnabled
_
Interface StabilityCommitted
_
MT-LevelMT-Safe
_
StandardSee \fBstandards\fR(5).
.TE
.SH SEE ALSO
.sp
.LP
\fBctime\fR(3C), \fBgetdate\fR(3C), \fBisspace\fR(3C), \fBmktime\fR(3C),
\fBsetlocale\fR(3C), \fBstrftime\fR(3C), \fBattributes\fR(5), \fBenviron\fR(5),
\fBstandards\fR(5)
|