PHP strftime() Function

Example

Format local date and time according to the locale:

<?php
echo(strftime("%B %d %Y, %X %Z",mktime(20,0,0,12,31,98))."<br>");
setlocale(LC_ALL,"hu_HU.UTF8");
echo(strftime("%Y. %B %d. %A. %X %Z"));
?>

Try it yourself

Definition and Usage

The strftime() function formats local date and time according to the locale.

Tip:See also gmstrftime() Function, formats GMT/UTC date and time according to the locale.

Syntax

strftime(format,timestamp);
Parameter Description
format

Required. Defines how the result is returned:

  • %a - Abbreviated weekday name
  • %A - Full weekday name
  • %b - Abbreviated month name
  • %B - Full month name
  • %c - Preferred date and time notation
  • %C - Century number (year divided by 100, range from 00 to 99)
  • %d - Day of the month (01 to 31)
  • %D - Date format, same as %m/%d/%y notation
  • %e - Day of the month (1 to 31)
  • %g - Similar to %G notation, but without century
  • %G - 4-digit year corresponding to ISO week number (see %V)
  • %h - Same as %b notation
  • %H - Hour, using 24-hour clock (00 to 23)
  • %I - Hour, using 12-hour clock (01 to 12)
  • %j - Day of the year (001 to 366)
  • %m - Month (01 to 12)
  • %M - Minutes
  • %n - Newline character
  • %p - am or pm corresponding to the given time value
  • %r - a.m. and p.m. time notation
  • %R - 24-hour time notation
  • %S - Seconds
  • %t - Tab character
  • %T - Current time, same as %H:%M:%S notation
  • 誒دد هفته‌های هفته، از یکشنبه به یکشنبه، Monday[یکشنبه] = 1. هشدار: در سیستم‌عامل Sun Solaris، Sunday[یکشنبه] = 1
  • %U - تعداد هفته‌های سال، از اولین هفته‌ای که با یکشنبه شروع می‌شود، به عنوان اولین هفته، حداقل باید چهار روز باشد و با یکشنبه شروع شود
  • %V - تعداد هفته‌های سال در فرمت ISO 8601 (01 تا 53)، هفته 1 به عنوان اولین هفته سال شناخته می‌شود، حداقل باید چهار روز باشد و با یکشنبه شروع شود
  • %W - تعداد هفته‌های سال، از اولین هفته‌ای که با یکشنبه شروع می‌شود، به عنوان اولین هفته، حداقل باید چهار روز باشد و با یکشنبه شروع شود
  • %w - عدد دسیمال روزهای هفته، Sunday[یکشنبه] = 0
  • %x - روش تاریخ پیش‌فرض بدون زمان
  • %X - روش زمانی پیش‌فرض بدون تاریخ
  • %y - سالی که شامل عدد قرن نیست (محدود به 00 تا 99)
  • %Y - سالی که شامل عدد قرن است
  • %Z یا %z - نام منطقه زمانی یا کوتاه‌شده
  • %% - خروج یک % رشته
timestamp اختیاری. زمان Unix برای تاریخ/زمان مورد نیاز را مشخص می‌کند. پیش‌فرض زمان فعلی است (time()()).

جزئیات فنی

بازگشت ارزش:

بازگشت بر اساس format استفاده از داده‌های timestamp رشته‌های فرمت‌گذاری شده.

نام ماه‌ها و روزهای هفته و رشته‌های مرتبط با زبان‌های دیگر setlocale() تنظیمات منطقه‌ای فعلی.

نسخه PHP: 4+
گزارش به‌روزرسانی‌ها: PHP 5.1.0: افزودن E_STRICT و E_NOTICE خطاهاي زمانی.