【问题标题】:I want display my post time at jalali date php format我想以 jalali 日期 php 格式显示我的发布时间
【发布时间】:2019-01-25 07:48:51
【问题描述】:

这里是 jdate 库jdate

我的 format.php 文件

<?php
/**
*Format Class
*/
class Format{
    public function formatDate($date){
        return date('F j, Y, g:i a', strtotime($date));
    }

    public function textShorten($text, $limit = 400){
        $text = $text. "";
        $text = substr($text, 0, $limit);
        $text = substr($text, 0, strrpos($text, ' '));
        $text = $text. "";
        return $text;
    }
}
?>

和我的发布日期代码

<h6><?php echo $fm->formatDate($result['date']); ?>, by<a href="#"><?php echo $result['author']; ?></a></h6>

如何使用 jdate 而不是公历时间。

【问题讨论】:

  • Small Point $text = $text. ""; 什么都不做,只是使用 cpu 周期
  • 第二个小点 没有明智的 SO 用户会下载未知的 zip 文件来回答问题。风险太高了。请以文本形式发布代码

标签: php jalali-calendar


【解决方案1】:

你应该包含 jdf.php 文件,然后只使用 jdate 而不是 date

<?php
/**
*Format Class
*/
include_once('jdf.php');
class Format{
  public function formatDate($date){
     return jdate('F j, Y, g:i a', strtotime($date));
  }

  public function textShorten($text, $limit = 400){
    $text = $text. "";
    $text = substr($text, 0, $limit);
    $text = substr($text, 0, strrpos($text, ' '));
    $text = $text. "";
    return $text;
  }
}
?>

更多信息和帮助,请参考this link

【讨论】:

  • ali 插入您的代码,但显示错误年份-->1348 出现此错误警告:在第 17 行的 C:\xampp\htdocs\helpers\jdf.php 中遇到非数字值跨度>
  • 第一条评论:您的日期格式是否正确?看到这个链接:stackoverflow.com/questions/50174713stackoverflow.com/questions/2891937
  • 第二条评论:也许你忘了在你的 index.php 中包含 jdf.php 或者你忘了在索引目录中复制那个文件
  • @Saeid,欢迎您。所以你可以接受和/或投票。如果需要编辑答案,请告诉我。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-12
  • 1970-01-01
  • 2017-04-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多