dsadsa123111 2017-01-10 08:07
浏览 24

如何在PHP中定义自己的日期格式?

Could you clarify me, how can I define my own date format in PHP ?

For instance, I have a date variable.

And I want to output this date as a date of the Ancient Roman calendar. Or in format of the French revolution calendar. These calendars, for example, begin not from the Christmas and have other names of months.

Also some calendars don't have weeks in 7 days, but have "weeks" in another quantity of days.

Or in format as "year and season". For example, "2016, the summer".

Is it possible to add a date format in PHP date formats and somehow code its output ?

  • 写回答

2条回答 默认 最新

  • dongyuan1970 2017-01-10 08:25
    关注

    It's possible just define your own function. the way I think most poeple would do this is by create a functions.php file where your store your function and other custom functions. Then include functions.php in the file where you want to display roman date. Then declare your function :

    function translateToRomanCalendar($date = ""){//declare function
    
       $romanDate = "";//declare roman date variable
    
       //Put the translation code here. Using tests and stuff to store 
       //the  roman date  in the romanDate variable
    
       return $romanDate;//return the roman date
    
    }
    

    Then just call that function in your php file: for example to display the translated current year you would do

    <?php echo translateToRomanCalendar(date('Y')) ?>
    

    This will echo the return value of the function ($romanDate's value).

    Now what will be tricky is the actual function's code; you have to test for date format and stuff.

    anyways hope that helps there is tons of material on the web about php functions.

    Regards

    Alex

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?