【问题标题】:Month from number to letter php if [duplicate]如果[重复]从数字到字母php的月份
【发布时间】:2014-02-08 11:30:51
【问题描述】:

表格中有月份

我想要一个执行此操作的 php 公式

if month = 6 -> $month1='June' if month = 7 -> $month1='July' if month = 8 -> $month1='August' if month = 9 -> $month1='Septmber'

【问题讨论】:

标签: php monthcalendar


【解决方案1】:

欢迎使用 PHP :)

$month_names = array (
    "jan", "feb", "mar", "apr", "may", "jun",
    "jul", "aug", "sep", "oct", "nov", "dec");

$name = $month_name[$month-1];

【讨论】:

    【解决方案2】:

    应该工作:

    $month = 5;
    $monthName = date("F", mktime(0, 0, 0, $month, 10));
    echo $monthName;
    

    【讨论】:

    • 谢谢它工作得很好!如果我喜欢用意大利语而不是英语获得月份,例如不是六月而是 Giugno
    【解决方案3】:

    为什么不使用日期时间对象:

    $month = 3;
    $monthName = DateTime::createFromFormat('m', $month)->format('F');
    echo $monthName;
    

    【讨论】:

    • 谢谢它工作得很好!如果我喜欢用意大利语而不是英语获得月份,例如不是六月而是 Giugno
    【解决方案4】:
    function getName($monthNumber){
       return date("F", strtotime("2014-".$monthNumber."-1 12:00:00"));
    }
    $month = 8 ; // <-- or any number you want
    echo getName($month);
    

    输出:八月

    【讨论】:

      猜你喜欢
      • 2020-07-17
      • 2011-06-04
      • 1970-01-01
      • 2017-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-10
      相关资源
      最近更新 更多