Java Timestamp Format formatDateTime(long ms)

Here you can find the source of formatDateTime(long ms)

Description

Return the time in GMT

License

Open Source License

Parameter

Parameter Description
ms the time in milliseconds

Return

The formatted date string

Declaration

public static String formatDateTime(long ms) 

Method Source Code

//package com.java2s;
/*//from   ww w .  j av a  2 s. co  m
 * Copyright (C) 2003-2007 Jost Boekemeier
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

import java.text.DateFormat;

import java.util.Locale;

import java.util.TimeZone;

public class Main {
    /**
     * Return the time in GMT
     *
     * @param ms the time in milliseconds
     * @return The formatted date string
     */
    public static String formatDateTime(long ms) {
        java.sql.Timestamp t = new java.sql.Timestamp(ms);
        DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, Locale.ENGLISH);
        formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
        String str = formatter.format(t);
        return str;
    }
}

Related

  1. formatDate(Timestamp time, String pattern)
  2. formatDate(Timestamp timestamp)
  3. formatDateHour(Date date)
  4. formatDateTime(Date date)
  5. formatDateTime(java.sql.Timestamp ts)
  6. formatDateTime(String dTime)
  7. formatDateTime(Timestamp t, String pattern)
  8. formatDateTimeStamp(final Date date)
  9. formatDateToTimestamp(String string)