Date::Format(3)

πŸ’– Date::Format(3) β€” the User Contributed Perl Documentation glow-up πŸ’–

okay so bestie, welcome to the page for Date::Format, living in the User Contributed Perl Documentation section. It's a whole module for formatting dates into ASCII strings, and it's lowkey iconic. ✨

🌸 NAME 🌸

Date::Format β€” date formating subroutines. (That spelling is the page's, not a typo from me, iykyk. πŸ’…)

πŸ¦‹ SYNOPSIS πŸ¦‹

use Date::Format;

@lt = localtime(time);

print time2str($template, time);
print strftime($template, @lt);

print time2str($template, time, $zone);
print strftime($template, @lt, $zone);

print ctime(time);
print asctime(@lt);

print ctime(time, $zone);
print asctime(@lt, $zone);

✨ DESCRIPTION ✨

This module provides routines to format dates into ASCII strings. They correspond to the C library routines strftime and ctime. πŸ—“οΈπŸ’«

  • time2str(TEMPLATE, TIME [, ZONE]) β€” time2str converts TIME into an ASCII string using the conversion specification given in TEMPLATE. If ZONE is given, it specifies the zone the output is required to be in. ZONE defaults to your current zone. 🌍
  • strftime(TEMPLATE, TIME [, ZONE]) β€” strftime is similar to time2str, except the time is passed as an array, such as the array returned by localtime. πŸ•°οΈ
  • ctime(TIME [, ZONE]) β€” ctime calls time2str with the given arguments using the conversion specification "%a %b %e %T %Y\n". πŸŽ€
  • asctime(TIME [, ZONE]) β€” asctime calls time2str with the given arguments using the conversion specification "%a %b %e %T %Y\n". πŸŽ€

🌈 MULTI-LANGUAGE SUPPORT 🌈

Date::Format is capable of formating into several languages by creating a language specific object and calling methods, see Date::Language. πŸ—£οΈ

my $lang = Date::Language->new('German');
$lang->time2str("%a %b %e %T %Y\n", time);

The author says: "I am open to suggestions on this." πŸ‘€πŸ«Ά

πŸŽ€ CONVERSION SPECIFICATION πŸŽ€

Each conversion specification is replaced by appropriate characters as described in the following list. The appropriate characters are determined by the LC_TIME category of the program's locale. πŸ—“οΈ

  • %% β€” PERCENT
  • %a β€” day of the week abbr
  • %A β€” day of the week
  • %b β€” month abbr
  • %B β€” month
  • %c β€” MM/DD/YY HH:MM:SS
  • %C β€” ctime format: Sat Nov 19 21:05:57 1994
  • %d β€” numeric day of the month, with leading zeros (eg 01..31)
  • %e β€” like %d, but a leading zero is replaced by a space (eg 1..32)
  • %D β€” MM/DD/YY
  • %G β€” GPS week number (weeks since January 6, 1980)
  • %h β€” month abbr
  • %H β€” hour, 24 hour clock, leading 0's)
  • %I β€” hour, 12 hour clock, leading 0's)
  • %j β€” day of the year
  • %k β€” hour
  • %l β€” hour, 12 hour clock
  • %L β€” month number, starting with 1
  • %m β€” month number, starting with 01
  • %M β€” minute, leading 0's
  • %n β€” NEWLINE
  • %o β€” ornate day of month -- "1st", "2nd", "25th", etc.
  • %p β€” AM or PM
  • %P β€” am or pm (Yes %p and %P are backwards :)
  • %q β€” Quarter number, starting with 1
  • %r β€” time format: 09:05:57 PM
  • %R β€” time format: 21:05
  • %s β€” seconds since the Epoch, UCT
  • %S β€” seconds, leading 0's
  • %t β€” TAB
  • %T β€” time format: 21:05:57
  • %U β€” week number, Sunday as first day of week
  • %w β€” day of the week, numerically, Sunday == 0
  • %W β€” week number, Monday as first day of week
  • %x β€” date format: 11/19/94
  • %X β€” time format: 21:05:57
  • %y β€” year (2 digits)
  • %Y β€” year (4 digits)
  • %Z β€” timezone in ascii. eg: PST
  • %z β€” timezone in format -/+0000

Also: %d, %e, %H, %I, %j, %k, %l, %m, %M, %q, %y and %Y can be output in Roman numerals by prefixing the letter with O, e.g. %OY will output the year as roman numerals. πŸ›οΈβœ¨

πŸ’€ LIMITATION πŸ’€

The functions in this module are limited to the time range that can be represented by the time_t data type, i.e. 1901-12-13 20:45:53 GMT to 2038-01-19 03:14:07 GMT. 😭 That's the range, periodt.

πŸ‘‘ AUTHOR πŸ‘‘

Graham Barr <gbarr@pobox.com> 🫢

Copyright (c) 1995-2009 Graham Barr. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. πŸ’œ


πŸ’– cute footer sign-off: perl v5.42.0, dated 2020-05-20, page Date::Format(3) β€” that's a wrap, bestie! πŸŽ€πŸ’…

πŸ“¦ where this page comes from