Java Date to String dateToUTCDate(Date d)

Here you can find the source of dateToUTCDate(Date d)

Description

date To UTC Date

License

Open Source License

Declaration

public static Date dateToUTCDate(Date d) 

Method Source Code

//package com.java2s;
/**//from   w w  w. ja v a  2s. c o m
  * Copyright (c) 2009 University of Rochester
  *
  * This program is free software; you can redistribute it and/or modify it under the terms of the MIT/X11 license. The text of the  
  * license can be found at http://www.opensource.org/licenses/mit-license.php and copy of the license can be found on the project
  * website http://www.extensiblecatalog.org/. 
  *
  */

import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    public static Date dateToUTCDate(Date d) {
        String strDate = "";
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(d);
        int utcOffsetInMinutes = -(calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET))
                / (60 * 1000);
        calendar.add(Calendar.MINUTE, utcOffsetInMinutes);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        return calendar.getTime();
    }
}

Related

  1. dateToStringWithFormat(Date dateToString, String dateFormat)
  2. dateToStringWithPattern(Date date, String pattern)
  3. dateToStringWithPattern(Date date, String pattern)
  4. dateToStringWithTime(Date date)
  5. dateToTimeString(Date date)
  6. dateToUtcString(Date date)
  7. dateToW3c(Date d)
  8. dateToW3CDTF(Date date)
  9. dateToW3CDTF(Date date)