توابع strftime() در PHP

مثال

تاریخ و زمان محلی را با استفاده از تنظیمات منطقه‌ای فرمت کنید:

<?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"));
?>

مثال اجرایی

تعریف و استفاده

تابع strftime() تاریخ و زمان محلی را بر اساس تنظیمات منطقه‌ای فرمت می‌کند.

نکته:لطفاً ببینید gmstrftime() تابع، تاریخ و زمان GMT/UTC را بر اساس تنظیمات منطقه‌ای فرمت می‌کند.

نحوه استفاده

strftime(format,timestamp);
پارامترها توضیح
format

ضروری. تعیین می‌کند که چگونه باید نتایج را بازگرداند:

  • %a - کوتاهترین نام روز هفته
  • %A - نام کامل روز هفته
  • %b - کوتاهترین نام ماه
  • %B - نام کامل ماه
  • %c - روش پیشفرض نمایش تاریخ و زمان
  • %C - عدد قرن (سال تقسیم بر 100، دامنه 00 تا 99)
  • %d - روزهای ماه (01 تا 31)
  • %D - فرمت زمان، مشابه %m/%d/%y
  • %e - روزهای ماه (1 تا 31)
  • %g - مشابه %G اما بدون قرن
  • %G - سال 4 رقمی که با شماره هفته ISO مطابقت دارد (ببینید %V)
  • %h - مشابه %b
  • %H - ساعت، با استفاده از سیستم 24 ساعته (00 تا 23)
  • %I - ساعت، با استفاده از سیستم 12 ساعته (01 تا 12)
  • %j - روزهای سال (001 تا 366)
  • %m - ماه (01 تا 12)
  • %M - دقیقه
  • %n - نشانه خط جدید
  • %p - am یا pm که با مقدار زمان داده شده مطابقت دارد
  • %r - روش علامت زمان صبح و عصر
  • %R - روش علامت زمان 24 ساعته
  • %S - ثانیه
  • %t - تاب
  • تاریخ فعلی - به صورت %T مشابه %H:%M:%S
  • 蒧umeric representation of the day of the week (1 to 7), Monday[Monday] = 1. Warning: In Sun Solaris systems, Sunday[Sunday] = 1
  • %U - The number of weeks contained in the year, starting from the first Sunday, as the first week, as the first day of the week
  • %V - The number of weeks contained in the year in ISO 8601 format (01 to 53), week 1 represents the first week of the year, at least four days, and Monday as the first day of the week
  • %W - The number of weeks contained in the year, starting from the first Monday, as the first week, with the first day of the week as Monday
  • %w - Decimal number representing the day of the week, Sunday[Sunday] = 0
  • %x - Preferred date representation without time
  • %X - Preferred time representation without date
  • %y - Year representation without a number representing the century (range from 00 to 99)
  • %Y - Year representation containing a number representing the century
  • %Z or %z - Timezone name or abbreviation
  • %% - Output a % character
timestamp Optional. Specifies the Unix timestamp representing the date/time to be formatted. The default is the current time (time())

Technical Details

Return Value:

returns based on format using the given timestamp formatted strings.

The names of months and weekdays, and strings related to other languages, comply with setlocale() current locale settings.

PHP Version: 4+
Update Log: PHP 5.1.0: Added E_STRICT and E_NOTICE timezone errors.