23-04-2014
công dụng: thời gian sẽ đổi thành dạng: vài giây trước, 1 giờ trc.. :63:
hướng dẫn
vào nơi bạn đặt code <xt:guestbook..
thêm format="Y.m.d H:i:s" nếu đã có format rồi thì chỉ việc sửa lại..
tiếp vào file .twig của bạn tìm đoạn code sau
{% macro comments_list (comments, ctx) %}
{% for comment in comments %}
copy đoạn code sau vào dưới code trên
{% set s=comment.date|slice(17,2) %}
{% set m=comment.date|slice(14,2) %}
{% set h=comment.date|slice(11,2) %}
{% set d=comment.date|slice(8,2) %}
{% set day=comment.date|slice(8,2) %}
{% set mo=comment.date|slice(5,2) %}
{% set y=comment.date|slice(0,4) %}
{% set time1=comment.date|slice(11,8) %}
{% set nowm="now"|date("s", "Asia/Ho_Chi_Minh") %}
{% if s <= "now"|date("s", "Asia/Ho_Chi_Minh") %}
{% set s="now"|date("s", "Asia/Ho_Chi_Minh")-s %}
{% else %}
{% set s,m="now"|date("s", "Asia/Ho_Chi_Minh")+60-s,m+1 %}{%endif%}
{% if m <= "now"|date("i", "Asia/Ho_Chi_Minh") %}
{% set m="now"|date("i", "Asia/Ho_Chi_Minh")-m %}
{% else %}
{% set m,h="now"|date("i", "Asia/Ho_Chi_Minh")+60-m,h+1 %}{%endif%}
{% if h <= "now"|date("H", "Asia/Ho_Chi_Minh") %}
{% set h="now"|date("H", "Asia/Ho_Chi_Minh")-h %}
{% else %}
{% set h,d="now"|date("H", "Asia/Ho_Chi_Minh")+24-h,d+1 %}{%endif%}
{% if d <= "now"|date("d", "Asia/Ho_Chi_Minh") %}
{% set d="now"|date("d", "Asia/Ho_Chi_Minh")-d+1 %}
{% else %}
{% set d,mo="now"|date("d", "Asia/Ho_Chi_Minh")+31-d,1 %}{%endif%}
{% if mo < nowm %}
{% if day=="now"|date("d", "Asia/Ho_Chi_Minh") %}
{% if h > 0%}{% set time %}{{ h~" giờ "~m~" phút" }} trước{% endset %}{%elseif h==0 and m > 0%}{% set time %}{{m~" phút "~s~" giây " }} trước{% endset %}{%else%}{% set time %}Vừa xong{% endset %}{%endif%}
{%elseif d<=1 %}{% set time %}Hôm qua lúc {{time1}} {% endset %}{%elseif d > 1 %}{% set time %}{{ d }} ngày trước lúc {{time1}}{% endset %}{% endif %}{%else%}{% set time %}{{comment.date}}{% endset %}{% endif %}
phần trên là ta đã lưu biến time cho phòng chat.. bây giờ muốn nó hiển thị ở đâu chỉ việc dán
{{time}}
là ok
code tự mod lại nên rất có thể còn lỗi..
copy xin ghi nguồn: godlike - gmvn.. :71: