Here you can find the source of formatTimeFromTimestamp(long ts, String fmt)
Parameter | Description |
---|---|
ts | a parameter |
fmt | a parameter |
public static String formatTimeFromTimestamp(long ts, String fmt)
//package com.java2s; /*//ww w . j av a2 s .c o m * Copyright 2015, Yahoo Inc. * Copyrights licensed under the Apache License. * See the accompanying LICENSE file for terms. */ import java.util.Date; import java.util.TimeZone; public class Main { /** * Format timestamp ts to string of format fmt, in UTC, for example, yyyy-MM-dd HH:mm:ss * @param ts * @param fmt * @return If failed, return empty string "" */ public static String formatTimeFromTimestamp(long ts, String fmt) { java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(fmt); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); try { return sdf.format(new Date(ts)); } catch (Exception ex) { } return ""; } }