Home php fix the date into Russian in php

fix the date into Russian in php

Author

Date

Category

Here is a fragment of the site http://joxi.ru/rmzbkeofwgml3m
It is necessary that instead of the name of the month in English. Language was displayed completely the name of the month with a small letter in Russian. How to do it?
Here is a fragment of code:

& lt; span class = "entry-time" & gt;
      & lt;? php
        $ expire_date = STRTOTIME (GET_POST_META ($ Post- & gt; ID, 'expire_date', true));
        If ($ expire_date):
          if ($ interval & gt; -86400 & amp; & amp; $ interval & lt; 0):
            Echo "The term expires:". "& lt; span class = \" expired-color \ "& gt;" Date ('M D, Y', StrTotime (get_post_meta ($ post- & gt; id, 'expire_date', true) )). "& lt; / span & gt;";
          ELSE:
            Echo "The term expires:" .date ('M D, Y', StrTotime (get_post_meta ($ post- & gt; id, 'expire_date', true))). '';
          endif;
        ELSE:
          Echo "The term expires: unknown";
        endif;
      ? & gt;
    & lt; / span & gt; & lt;! - .ENTRY-TIME - & gt;

Answer 1, Authority 100%

date (‘n’) Accepts the Format parameter with the n value. Where N This is a sequence number of the month without a leading zero from 1 to 12.

$ arr = [
 'January',
 'February',
 'March',
 'April',
 'May',
 'June',
 'July',
 'August',
 'September',
 'October',
 'November',
 'December'
];
// because from 1 to 12, and in the array, as we know, the counting comes from zero (0 to 11),
// I deduct 1 to choose to choose from our array.
$ MONTH = DATE ('N') - 1;
Echo $ Arr [$ MONTH]. ' '.date (' D, Y ');

Answer 2, Authority 25%

Two options:
1) SETLOCALE + STRFTIME

setlocale (lc_all, 'ru_ru', 'ru_ru.utf-8', 'ru', 'russian') ;
Echo Strftime ("% B% d,% y", time ());

Of the minuses – it will only work if the system has the desired locale

2) array of names of months + getdate

$ TR_M = ['NUNEBER' / * for the index shift by +1 * /, 'january', 'February ',' MART ', ....' December '];
$ exp_date = get_post_meta (GET_POST_META ($ Post- & gt; id, 'expire_date', true)));
$ Full_Datedate = Sprintf (
    '% s% d,% d',
    $ TR_M [$ exp_date ['mon']]
    $ EXP_DATE ['MDay'],
    $ EXP_DATE ['year']
);

from minuses – more code.


Answer 3, Authority 12%

function ymdw ($ param1 = null, $ param2 = null) {
// --------------------------------------
// This feature works only in a bundle with the "rus_date" function http://webi.ru/webi_files/rus_date.html
// --------------------------------------
// Y - year
// M - Month
// D - day
// W - name of the day of the week
// --------------------------------------
// YMDW () - Conclusion: 2019-08-30 (current date)
// YMDW ("") - Conclusion: 2019-08-30 (current date)
// YMDW ("2019-08-30") - Conclusion: August 30 (Friday), 2019 (asked date)
// YMDW (YMDW ()) - Conclusion: August 30 (Friday), 2019 (current date)
// YMDW ("TMSP") - Conclusion: 1567155817 // TIME OF TIME OF THE UNIX CURRENT DATE AND TIME (TICET) (Current)
// YMDW ("Y") - Conclusion: 2019 (current)
// YMDW ("M") - Conclusion: number of month (from 1 to 12) (current)
// YMDW ("MN") - conclusion: the name of the month (current)
// YMDW ("D") - Conclusion: Date of the month (from 1 to 31) (current)
// YMDW ("DN") - Conclusion: Name of the Day of the Week (Monday) (Current)
// YMDW ("2019-08-30", "TMSP") - Conclusion: 1567155817 // Tag of the Time Unix current date
// YMDW ("2019-08-30", "Y") - Conclusion: Year (number)
// YMDW ("2019-08-30", "M") - Conclusion: number of month (from 1 to 12)
// YMDW ("2019-08-30", "Mn") - Conclusion: the name of the month (January)
// YMDW ("2019-08-30", "D") - Conclusion: Date of the month (from 1 to 31)
// YMDW ("2019-08-30", "DN") - output: name of the day of the week (Monday)
// YMDW ("1559682000", "") - Conclusion: June 5 (Wednesday) 2019 
// YMDW ("1559682000", "Y") - Conclusion: 2019
// YMDW ("1559682000", "M") - Conclusion: number of month (from 1 to 12)
// YMDW ("1559682000", "MN") - Conclusion: Name of the month
// YMDW ("1559682000", "D") - Conclusion: Date of the month (from 1 to 31)
// YMDW ("1559682000", "DN") - Conclusion: Name of the Day of the Week (Monday)
// --------------------------------------
date_default_timezone_set ("europe / volgograd"); // Set Default Time Zone / VOLGOGRAD / SAMARA /
$ Args = Func_Get_Args (); // Array Arguments Function
$ year = substr ($ param1, 0, 4); // Year
$ MONTH = substr ($ param1, 5, -3); // number of the month
$ month_name = rus_date ("f", mktime (0, 0, 0, int) $ month, 10)); // Name of the month
$ day = substr ($ param1, 8); // number of month
$ get_week_day = rus_date ("L", StrTotime ($ param1)); // Day of the week
$ timestamp = STRTOTIME ($ param1); // Time Tag Unix
// --------------------------------------
// Current Date (2019-08-30)
If (Count ($ args) == 0) {
  RETURN DATE ("Y-M-D");
} ELSEIF ($ param1 == "") {
  RETURN DATE ("Y-M-D");
} elseif ($ param1! = "") {
  // June 5 (Sunday), 1977
  if (preg_match ("# ([0-9] {4,4}) - ([0-9] {2,2}) - ([0-9] {2,2}) #", $ param1) ) {
    if ($ param2! = "") {
      if ($ param2 == "TMSP") {
        RETURN STRTOTIME (Date ($ param1));
      } ELSEIF ($ param2 == "Y") {
        RETURN SUBSTR ($ param1, 0, 4);
      } ELSEIF ($ param2 == "M") {
        RETURN SUBSTR ($ param1, 5, -3);
      } ELSEIF ($ param2 == "D") {
        RETURN SUBSTR ($ param1, 8);
      } elseif ($ param2 == "Mn") {
        RETURN RUS_DATE ("F", MkTime (0, 0, 0, (int) substr ($ param1, 5, -3), 10));
      } ELSEIF ($ param2 == "DN") {
        RETURN RUS_DATE ("L", StrTotime ($ param1));
      }
    } else {
      Return (int) $ day. "". $ MONTH_NAME. "(". $ get_week_day. "),". $ year. " G.";
    }
  } elseif (preg_match ("# ^ [0-9] {5.20} $ #", $ param1)) {
     if ($ param2! = "") {
      // Year (number)
      if ($ param2 == "y") {
        RETURN DATE ("Y", $ param1);
      }
      // number of the month (from 1 to 12)
      Elseif ($ param2 == "M") {
        RETURN (INT) DATE ("M", $ param1);
      }
      // Date of the month (from 1 to 31)
      Elseif ($ param2 == "D") {
        Return (int) Date ("D", $ param1);
      }
      // Name of the month
      ELSEIF ($ param2 == "Mn") {
        Return rus_date ("f", mktime (0, 0, 0, (int) date ("m", $ param1), 10));
      }
      // Name of the day of the week (Monday)
      Elseif ($ param2 == "DN") {
        Return rus_date ("L", mktime (0, 0, 0, (int) date ("D", $ param1), 10));
      }
    }
    // Conclusion: August 30 (Friday), 2019
    ELSE {
      RETURN (INT) DATE ("D", $ param1). "". rus_date ("f", $ param1). "(". rus_date ("L", $ param1). ")". Date ("Y", $ param1). " G.";
    }
  } else {
    // Tag Time Tag Unix Current Date and Time
    if ($ param1 == "TMSP") {
      RETURN TIME ();
      // Return StrTotime ("NOW");
    }
    // This year
    Elseif ($ param1 == "Y") {
      RETURN DATE ("Y");
    }
    // Current month
    Elseif ($ param1 == "M") {
      RETURN (INT) DATE ("M");
    }
    // Name of the month
    Elseif ($ param1 == "MN") {
      RETURN RUS_DATE ("F", TIME ());
    }
    // This day
    Elseif ($ param1 == "D") {
      RETURN (INT) DATE ("D");
    }
    // Name of the day of the week (Monday)
    Elseif ($ param1 == "DN") {
      RETURN RUS_DATE ("L", TIME ());
    }
  }
}

}


Answer 4, Authority 12%

What is written in the comments as the answers – do not need to do so. How to do is needed – there is an extension for PHP Intl . Make sure it is included PHP -M

There is a special intldateFormatter you initialize with the settings you need.

$ date = new datetime ();
$ intlformatter = new intldateformatter ('ru_ru', intldateformatter :: short, intldateformatter :: short);
$ intlformatter- & gt; setpattern ('mmmm');
Echo $ intlformatter- & gt; Format ($ Date);

via formater Documentation here
By patterns, you can see here

p.s. Wuhaha and this is a duplicate answer in a duplicate question!


Answer 5

found the decision itself, checked works:

& lt; span class = "entry-time" & gt;
& lt;? php
$ Date_M = Array ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'November', ' December');
$ expire_date = STRTOTIME (GET_POST_META ($ Post- & gt; ID, 'expire_date', true));
if ($ expire_date) {
  if (($ interval & gt; -86400) & amp; & amp; ($ interval & lt; 0))
    Echo 'term expires: & lt; span class = "expired-color" & gt;' . $ DATE_M [DATE ('N', $ expire_date) - 1]. ". Date ('D, Y', $ Expire_Date). '& lt; / span & gt;';
  ELSE.
    Echo 'term expires:'. $ DATE_M [DATE ('N', $ expire_date) - 1]. ". date ('d, y', $ expire_date);
} ELSE.
  Echo 'term expires: unknown';
? & gt;
& lt; / span & gt; & lt;! - .ENTRY-TIME - & gt;

Answer 6

You can use a localized date through the date_i18n () function , for example: date_i18n ('j f y') – will display the date in the current language.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions