简体   繁体   English

在手机上更改日期格式?

[英]Change date format on mobile?

I have a web application that uses PHP to pull from a MySQL Database and display a table.我有一个 Web 应用程序,它使用 PHP 从 MySQL 数据库中提取并显示一个表。 The date format displayed is M\\(m\\) j, Y g:ia (example: Dec(12) 31, 1969 4:00 pm).显示的日期格式为M\\(m\\) j, Y g:ia (例如:Dec(12) 31, 1969 4:00 pm)。

There's three columns of date data, and on mobile that make the table just too wide.有三列日期数据,在移动设备上,表格太宽了。 What would be the best way of using CSS to convert that long date format into a shorter date format on mobile?在移动设备上使用 CSS 将长日期格式转换为较短日期格式的最佳方法是什么?

Thanks.谢谢。

You can use different approaches.您可以使用不同的方法。 One is to generate with PHP the desktop version and the mobile version, and hiding through CSS the one not matching the current device.一种是用PHP生成桌面版和移动版,通过CSS隐藏当前设备不匹配的那个。

A simple example using the current date and 768px as the point where to change:使用当前日期和 768px 作为更改点的简单示例:

<table>
 <tbody>
 <tr>
   <td>your other stuff</td>
   [...]
   <td>
     <span class="desktop-date"><?php echo date('M\(m\) j, Y g:i a'); ?></span>
     <span class="mobile-date"><?php echo date('d-m-Y'); ?></span>
   </td>
  </tr>
  </tbody>
</table>

and then using CSS:然后使用 CSS:

@media (max-width: 767px) {
    .desktop-date {
      display: none;
    }
}
@media (min-width: 768px) {
    .mobile-date {
      display: none;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM