search

Home  >  Q&A  >  body text

java - Timestamp类型的"2016-03-29 10:20:34.0"怎么去掉后面多余的.0.只要到秒

Timestamp类型的"2016-03-29 10:20:34.0" 有什么方法可以把后面的毫秒去掉吗??
只要"2016-03-29 10:20:34"

谢谢!!!

PHPzPHPz2911 days ago394

reply all(1)I'll reply

  • PHPz

    PHPz2017-04-18 09:42:08

    For JSP pages, you can use tags to format them:

    <fmt:formatDate value="${xxxxxx}" pattern="yyyy-MM-dd HH:mm:ss"/>

    TimeStamp can be converted to String type in Java. For conversion, please refer to:

    public String timeSplitMs(Timestamp ts) {
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            if (null != ts) {
                return sdf.format(ts);
            }
        } catch (Exception e) {
            logger.warn("TimeStamp转换String格式出错", e);
        }
        return null;
    }

    reply
    0
  • Cancelreply