asctime()
Return the date and time as a character string.
Syntax
Parameter
Parameter | Definition |
---|---|
clock | reference to the clock or timer whose value should be converted to a character string The clock is most commonly time(). |
format | optional format symbol for the asctime() output string. For some common field symbols, see the following table for Format Symbols for asctime() Default |
Description
The asctime() function returns the date/time of clock as a character string. It is equivalent to the C library asctime() function except that the PSL asctime()function adjusts the value to the local timezone. If format is given, asctime()returns the date/time string in the specified format.
Format Symbols for asctime()
Format | Description |
---|---|
%% | allows you to use a percent sign (%) in the format of a date string |
%a | locale's abbreviated name of the day of week |
%A | locale's full name of the day of week |
%b | locale's abbreviated name of the month |
%B | locale's full name of the month |
%c | locale's appropriate date and time representation |
%C | data and time as %c |
%d | day of month [1,31]; single digits are preceded by 0 |
%D | date as %m/%d/%y |
%e | day of month [1,31]; single digits are preceded by a space |
%h | locale's abbreviated name of the month |
%H | hour (24-hour clock) [0,23]; single digits are preceded by 0 |
%I | hour (12-hour clock) [1,12]; single digits are preceded by 0 |
%j | day of year [1,366]; single digits are preceded by 0 |
%k | hour (24-hour clock) [0,23]; single digits are preceded by a space |
%l | hour (12-hour clock) [1,12]; single digits are preceded by a space |
%m | month as a decimal number [1,12]; single digits are preceded by 0 |
%M | minute [0,59]; leading zero is permitted but not required |
%n | insert a new line |
%p | locale's equivalent of either a.m. or p.m. |
%r | appropriate time representation in 12-hour clock format with %p |
%R | time as %H:%M |
%S | seconds [0,61] |
%t | insert a tab |
%T | time as %H:%M:%S |
%u | day of week as a decimal number [1,7], with 1 representing Monday |
%U | week of the year as a decimal number [0,53], with Sunday as the first day of week 1 |
%V | week of the year as a decimal number [01,53], with Monday as the first day of the week If the week containing 1 January has four or more days in the new year, it is considered week 1; otherwise, it is week 53 of the previous year, and the next week is week 1. |
%w | day of week as a decimal number [0,6], with 0 representing Sunday |
%W | week of the year as a decimal number [0,53], with Monday as the first day of week 1 |
%x | locale's appropriate date representation |
%X | locale's appropriate time representation |
%y | year within century [0,99] |
%Y | year, including the century (for example 1993) |
%Z | abbreviated or full name of time zone, or no bytes if no information of the time zone exists |
%Ec | locale's alternative appropriate date and time representation |
%EC | name of the base year (period) in the locale's alternative representation |
%Ex | locale's alternative date representation |
%EX | locale's alternative time representation |
%Ey | offset from %EC (year only) in the locale's alternative representation |
%EY | alternative representation of the year in full |
%Od | day of the month using the locale's alternative numeric symbols |
%Oe | same as %Od |
%OH | hour (24-hour clock) using the locale's alternative numeric symbols |
%OI | hour (12-hour clock) using the locale's alternative numeric symbols |
%Om | month using the locale's alternative numeric symbols |
%OM | minutes using the locale's alternative numeric symbols |
%OS | seconds using the locale's alternative numeric symbols |
%OU | week of the year (Sunday as the first day of the week) using the locale's alternative numeric symbols |
%Ow | day of week (Sunday=0) using the locale's alternative numeric symbols |
%OW | week of the year (Monday as the first day of the week) using the locale's alternative numeric symbols |
%Oy | year (offset from %C) in the locale's alternative representation and using the locale's alternative numeric symbols |
Example
The following PSL script shows how the asctime() function can translate the computer system time value into a familiar Gregorian date and time:
default_output = asctime(raw_time);
printf("raw time is %d, default asctime() output is %s\n",raw_time,default_output);
output_with_format = asctime(raw_time, "Day is %A, Month is %B, Time is %X\nTimezone is %Z");
printf("%s\n",output_with_format);
The preceding example returns the following output:
Day is Monday, Month is March, Time is 08:13:08 Timezone is CST