Java Date Format convertDateToUTC(Date date)

Here you can find the source of convertDateToUTC(Date date)

Description

Converts the given date to the UTC time zone so that dates can be correctly converted on the client side

License

Open Source License

Parameter

Parameter Description
date a parameter

Return

the message

Declaration

public static String convertDateToUTC(Date date) 

Method Source Code

//package com.java2s;
/*/* w w  w  .j a v  a  2s .c o  m*/
 * #%L
 * BroadleafCommerce Common Libraries
 * %%
 * Copyright (C) 2009 - 2016 Broadleaf Commerce
 * %%
 * Licensed under the Broadleaf Fair Use License Agreement, Version 1.0
 * (the "Fair Use License" located  at http://license.broadleafcommerce.org/fair_use_license-1.0.txt)
 * unless the restrictions on use therein are violated and require payment to Broadleaf in which case
 * the Broadleaf End User License Agreement (EULA), Version 1.1
 * (the "Commercial License" located at http://license.broadleafcommerce.org/commercial_license-1.1.txt)
 * shall apply.
 * 
 * Alternatively, the Commercial License may be replaced with a mutually agreed upon license (the "Custom License")
 * between you and Broadleaf Commerce. You may not use this file except in compliance with the applicable license.
 * #L%
 */

import java.text.SimpleDateFormat;
import java.util.Date;

import java.util.TimeZone;

public class Main {
    public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.s";

    /**
     * Converts the given date to the UTC time zone so that dates can be correctly converted on the client side
     * 
     * @param date
     * @return the message
     */
    public static String convertDateToUTC(Date date) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                DEFAULT_DATE_FORMAT);
        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

        return dateFormat.format(date);
    }
}

Related

  1. convertDateToString(Date dateObject, String dateFormat)
  2. convertDateToStringByFormat(Date date)
  3. convertDateToStringT(final Date date)
  4. convertDateToStringUI(Date data)
  5. convertDateToText(Date date)
  6. convertDateToXSDString(Date date)
  7. convertDayToString(Date aDate)
  8. dateFmtToString(Date date, SimpleDateFormat fmt)
  9. dateFormat(Date d, String formatStr)