Getting today's date in GMT time zone

Hi,
I have a simple question, but am confused how to do it:
I need the current GMT date (as a Date object) ..how do I do it?
Date date = new Date();
This returns the current date but according to the timezone of the system time & not GMT.
Using SimpleDateFormat comes close but it returns as a String object:
SimpleDateFormat dateFormat = new SimpleDateFormat("some format");
dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
Date date = new Date();
String dateAsString = dateFormat.format(date);
This gets the current GMT date but as a String object, but I want it as a Date object.
Can you please throw some light on this? I guess there should be simple way to do it or am overlooking something.
Thanks!

I don't think Calendar is useful here.
"Current date as GMT" is meaningless. Current date (and time) is just "now." Timezone is not part of the picture. If you want to present the current date/time in GMT, then....
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm z");
System.out.println(df.format(date));
df.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(df.format(date));
2007-06-04 02:29 PDT
2007-06-04 09:29 GMT

Similar Messages

  • How to use GregorianCalendar to get today's date?

    I am using the following code to get today's date? I'm curious whether there is a direct way for GregorianCalendar to get today's date?
    Thanks,
    java.util.Date today = new java.util.Date();
    Calendar cal_today = new GregorianCalendar();
    cal_today.setTime(today);
    System.out.println(" month = " + cal_today.get(Calendar.MONTH));
    System.out.println(" day = " + cal_today.get(Calendar.DAY_OF_MONTH));
    System.out.println(" year = " + cal_today.get(Calendar.YEAR));

    If you mean construct it with todays date and time, sure. Just call the contructor with no arguments. According to the API...Constructs a default GregorianCalendar using the current time in the default time zone with the default locale.

  • Getting today's date

    I'm too lazy to look this up right now, but what's the code to get today's date? (at least I'm honest :D)

    I'm too lazy to look this up right now, but what's the
    code to get today's date? (at least I'm honest :D)It probably would have taken you less time to look it up in the API, then to post here. :)

  • Always return GMT Time Zone in Bundle Image Deployment

    I have application that need to get window PC time zone, when use Bundle Image Deployment (include runtime jre), it always return GMT time zone no matter which time zone I set on my PC. After I replace runtime/jre in the image folder with complete jre, then it returns time zone correctly. Is it a bug in bundle deployment?
    javafx.runtime.version: 2.2.7-b01
    jdk1.7.0_17
    window 8 64bit
    Thanks.
    Eric

    I am experiencing similar type of issue.  I subscribed to a Calendar which has scheduled meeting from my time zone and different time zone.  When I subscribe in OS X, it shows flawlessly on local time. But when I do it in IOS 7,  it shows MST as-is in EST time zone and no matter we play around all the time zone setting in General tab or Mail/Calendar tab.  It's not helping.
    Appears to be a bug in IOS 7.  It needs to be reported to Apple.

  • I have a string 2012-05-22T23:23:42.263-07:00. so i want to convert in date with indian time zone   can any one help me out

    i have a string 2012-05-22T23:23:42.263-07:00. so i want to convert in date with indian time zone   can any one help me out

    What does this have to do with iPhone tech support?

  • How to get only the date without the time in the footer of a printout?

    Is there a way to get only the date without the time in the footer of a printout?

    As far as I can tell, there's no built-in option to get the date printed without the time. It's hardcoded in a C++ file.
    As a workaround, you can enter custom text for the footer, but it would need to be updated every time the date changed. I can think of a couple ways to automate that:
    * An add-on (but I'm not aware of any add-on for this)
    * External process to push a new date into prefs.js, a settings file that stores your header/footer preferences, among others (but Firefox should be closed when you update this file, and it will be read when you restart)
    Not easy enough, I know.

  • GMT time zone keeps coming up

    When entering an appointment in the calendar, it automatically comes up as GMT Time Zone.  I have tried various options; gone to the Apple Store, and checked online.  Response is that it's a bug with iOS8 and a fix is coming.  Is that the case?  I believe I only started having this problem after going to the iOS8 software.

    rmeryl wrote:
    When entering an appointment in the calendar, it automatically comes up as GMT Time Zone.  I have tried various options; gone to the Apple Store, and checked online.  Response is that it's a bug with iOS8 and a fix is coming.  Is that the case?  I believe I only started having this problem after going to the iOS8 software.
    This is a well known problem, one post has over 35 pages.  Basically it looks like an iOS problem with certain external calendar systems (Google Calendar being the most common).  Hopefully Apple will fix it some day.

  • Why are my apple calendars using GMT time zone?

    My iPhone and iPad are using the GMT time zone. Why???

    I'd like to bump this and add to it....We have a 30Mbps broadband connection with Aiport Express providing the wireless. When Apple TV is streaming Netflix, all other devices are virtually useless. I test each device on speedtest.net and they are all now 1-2Mbps and less, often stalling out. HOWEVER, if I stream Netflix on my wirelessly connected Mac Mini, all other devices consistently test at 22Mbps+. What is going on? I'm tempted to toss my Apple TV. Any time someone uses the Apple TV, the internet slows to a crawl, AirPlay stutters and stops, etc. Shut off Apple TV and we can simultaneously stream Netflix, etc. on 5 devices and the internet runs smooth. It makes no sense why Apple TV is doing this but I have tested it and 100% of the time, Apple TV is the culprit.

  • Why does my iPod say Connot connect to the iTunes store when my iPod is up to date and the time zone is okay

    why does my iPod say Connot connect to itunes store, when my iPod is up to date and my time zone is okay?

    Hey Hiika,
    Do not forget to check the Date and Time and make sure that it is set to Automatically. Check out the article below to troubleshoot your issue further.
    Can't connect to the iTunes Store
    http://support.apple.com/en-us/HT201400
    Take care,
    -Norm G. 

  • ICal events stuck on GMT time zone on 10.7.5

    I have mac OS X 10.7.5. When I download an invite from Evite, or TripIt. The items comes to my iPhone in the correct timezone, but not on my iMac. My iMac defaults to GMT. i have updated the preferecens, added time zone support, and it still loads in GMT. How do I fix this?  iCal is version 5.0.3.  I think the issue only comes when I download invitations from others.

    First since your iMac is running OS 10.7.5, you have an Intel-based iMac, and yu posted this thread in a forum for PowerPC (pre-Intel-Based) iMacs.  So you might not get many responses.
    I have one suggestion, and I'm not sure it will help, but try this and see if it helps.
    Open your System Preferences.  Clcik on Date and Time, make sure you have the correct time zone setting, the click the open lock in the bottom leftof the window, to lock the settings from being changed.  To open the lock later, you'll need totype in your system password.
    I doubt this the actual correct fix for your problem, but it might help in the mean time.
    Good luck.

  • Get today's date?

    I have an XML dataset that shows a schedule of events.  My page uses a yui calendar widget to get the events for specific selected days.  On load, the page shows all "events" that are listed in the XML file.  I am trying to set up a filter that will only show the events for today and days after today, on loading.  How do you set a variable to have the value of today's date, without explicitly typing in "10/30/2009?"  I don't want to call the filterData() function, because I still want to see what was scheduled in the past by selecting the dates in the calendar.  Any ideas would be greatly appreciated.
    Here is my code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:spry="http://ns.adobe.com/spry">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script src="SpryAssets/xpath.js" type="text/javascript"></script>
    <script src="SpryAssets/SpryData.js" type="text/javascript"></script>
    <script src="SpryAssets/SpryDataExtensions.js" type="text/javascript"></script>
    <script src="yui/2.6.0/build/yahoo-dom-event/yahoo-dom-event.js" type="text/javascript"></script>
    <script src="yui/2.6.0/build/calendar/calendar-min.js" type="text/javascript"></script>
    <script src="SpryAssets/SpryDOMUtils.js" language="javascript" type="text/javascript"></script>
    <script type="text/javascript">
    <!--
    var dsEvents = new Spry.Data.XMLDataSet("schedule.xml", "events/event", {sortOnLoad: "date", sortOrderOnLoad: "ascending"}  );
    dsEvents.setColumnType("date", "date");
    dsEvents.setColumnType("@id", "number");//-->
    </script>
    <link href="yui/2.6.0/build/fonts/fonts-min.css" rel="stylesheet" type="text/css" />
    <link href="yui/2.6.0/build/calendar/assets/skins/sam/calendar.css" rel="stylesheet" type="text/css" /></head><body>
    <div id="Schedule">
      <div id="yuicalendar1"></div>
      <script type="text/javascript">
    // BeginWebWidget YUI_Calendar: yuicalendar1   (function() {
        var cn = document.body.className.toString();
        if (cn.indexOf('yui-skin-sam') == -1) {
          document.body.className += " yui-skin-sam";
      var inityuicalendar1 = function() {
        var yuicalendar1 = new YAHOO.widget.Calendar("yuicalendar1");    // The following event subscribers demonstrate how to handle
        // YUI Calendar events, specifically when a date cell is
        // selected and when it is unselected.
        // See: http://developer.yahoo.com/yui/calendar/ for more
        // information on the YUI Calendar's configurations and
        // events.
        // The YUI Calendar API cheatsheet can be found at:
        // http://yuiblog.com/assets/pdf/cheatsheets/calendar.pdf
        //--- begin event subscribers ---//
        yuicalendar1.selectEvent.subscribe(selectHandler, yuicalendar1, true);
        yuicalendar1.deselectEvent.subscribe(deselectHandler, yuicalendar1, true);
        //--- end event subscribers ---//
    yuicalendar1.render();
      }  function selectHandler(event, data) {
      // The JavaScript function subscribed to yuicalendar1.  It is called when
      // a date cell is selected.
      // alert(event) will show an event type of "Select".
      // alert(data) will show the selected date as [year, month, date]. 
      var formattedDate = data[0][0][1] + "/" + data[0][0][2] + "/" + data[0][0][0];
      var dateFilterFunc = function(dsEvents, row, rowNumber)
    if (row["date"].search(formattedDate) != -1)
       return row; // Return the row to keep it in the data set.
    return null; // Return null to remove the row from the data set.
      dsEvents.filter(dateFilterFunc); // Filter the rows in the data set.
      };  function deselectHandler(event, data) {
      // The JavaScript function subscribed to yuicalendar1.  It is called when
      // a selected date cell is unselected.
      };      // Create the YUI Calendar when the HTML document is usable.
      YAHOO.util.Event.onDOMReady(inityuicalendar1);
    // EndWebWidget YUI_Calendar: yuicalendar1
      </script>
    <div spry:region="dsEvents">
      <table cellpadding="2" id="Events">
        <tr>
          <th spry:sort="name">Name</th>
          <th spry:sort="date">Date</th>
          <th spry:sort="starttime">Start Time</th>
          <th spry:sort="endtime">End Time</th>
          <th spry:sort="location">Location</th>
          <th spry:sort="type">Type</th>
          <th spry:sort="contact">Contact</th>
          <th spry:sort="@id">Id</th>
        </tr>
        <tr spry:repeat="dsEvents">
          <td>{name}</td>
          <td>{date}</td>
          <td>{starttime}</td>
          <td>{endtime}</td>
          <td>{location}</td>
          <td>{type}</td>
          <td>{contact}</td>
          <td>{@id}</td>
        </tr>
      </table>
    </div>
    </div>
    </body>
    </html>
    And here is my XML file:
    <?xml version="1.0" encoding="utf-8"?>
    <events>
    <event id="1">
      <name>Dreamweaver CS4 Intermediate</name>
      <date>10/15/2009</date>
      <starttime>8:00 am</starttime>
      <endtime>5:00 pm</endtime>
      <location>Room 1</location>
      <type>Training</type>
      <contact>Contact 1</contact>
    </event>
    <event id="2">
      <name>InDesign CS4 Advanced</name>
      <date>10/14/2009</date>
      <starttime>8:00 am</starttime>
      <endtime>5:00 pm</endtime>
      <location>Room 2</location>
      <type>Training</type>
      <contact>Contact 1</contact>
    </event>
    <event id="3">
      <name>Flex CS4 Data Services</name>
      <date>10/15/2009</date>
      <starttime>1:00 pm</starttime>
      <endtime>5:00 pm</endtime>
      <location>Room 2</location>
      <type>Meeting</type>
      <contact>Contact 2</contact>
    </event>
    <event id="4">
      <name>Another Dreamweaver CS4 Intermediate</name>
      <date>10/30/2009</date>
      <starttime>8:00 am</starttime>
      <endtime>5:00 pm</endtime>
      <location>Room 1</location>
      <type>Training</type>
      <contact>Contact 1</contact>
    </event>
    <event id="5">
      <name>Another InDesign CS4 Advanced</name>
      <date>10/29/2009</date>
      <starttime>8:00 am</starttime>
      <endtime>5:00 pm</endtime>
      <location>Room 2</location>
      <type>Training</type>
      <contact>Contact 3</contact>
    </event>
    <event id="6">
      <name>Another Flex CS4 Data Services</name>
      <date>10/28/2009</date>
      <starttime>1:00 pm</starttime>
      <endtime>5:00 pm</endtime>
      <location>Room 2</location>
      <type>Meeting</type>
      <contact>Contact 2</contact>
    </event>
    </events>

    Hi,
    Here is my code for attaching the event highlighting to the YUI calendar.  It is triggered via an observer everytime the SpryData region markup containing the event tooltips is regenerated on my first tab.  I've also include the code I wrote for adding tooltips based on SpryData. Note I amended the Sprytooltip.js dataset to speed up the rendering based on the tip Arnout gave me
    One thing I do which is not the default for YUI calendar is I namespace my calendar so I can access it whilst doing my Spry stuff.
    YAHOO.namespace("cal");
    YAHOO.cal.yuicalendar1 = new YAHOO.widget.CalendarGroup("yuicalendar1","yuical1group", {PAGES:12,START_WEEKDAY:1});
    var myObserver = new Object;
    myObserver.onPostUpdate = function(notify, data)
    // Get Spry Data into rows variable
    rows = Events.getData();
    // Yahoo YUI stuff
    YAHOO.cal.yuicalendar1.removeRenderers();
    for (var i = 2; i < rows.length; i++)
      // Convert in date format range that yui calendar recognises
      var s = new Date(rows[i]["StartDate"]);
      s = s.getMonth() + 1 + '/' + s.getDate() + '/' + s.getFullYear();
      var e = new Date(rows[i]["EndDate"]);
      e = e.getMonth() + 1 + '/' + e.getDate() + '/' + e.getFullYear();
      var cald = s + '-' + e;
      // Add highlight to range of cells   
      YAHOO.cal.yuicalendar1.addRenderer(cald, YAHOO.cal.yuicalendar1.renderCellStyleHighlight1);
        // Now add tool tips
    // Build array of contiguous dates based on HMC events
    // Now cycle through HMC events  
      eventDates = [];
      for (var r=2;r<rows.length;r++)
        startDate = new Date(rows[r]["StartDate"]);
        endDate = new Date(rows[r]["EndDate"]);
        while (startDate <= endDate)
         startDatestr = todayFormat(startDate);
           eventDates[startDatestr] = r;
         startDate.setDate(startDate.getDate() + 1);
    // cycle through each of the 12 months.
    for (var c=0;c<=11;c++)
        addTipFast(c);
    // now render
    YAHOO.cal.yuicalendar1.render();
    function addTipFast(c)
       // reference to calendar
       var calDate = new Date();
       var cal = YAHOO.cal.yuicalendar1.pages[c];
       var calID = cal.id;
       var calDates = cal.cellDates
       var selector = 'table#' + calID + ' td[class~="calcell"]'
       // return array reference to table cells that make up calendar
          tds = Spry.$$(selector);
       // Search for match on event table
         for (var r=0;r<calDates.length;r++)
        tYear = calDates[r][0];
        tMonth = calDates[r][1];
        if (tMonth == 0)
         tMonth = 12;}
       else
        tMonth = tMonth - 1;
        tDate = calDates[r][2];
        calDate.setFullYear(tYear,tMonth,tDate);
        nDate = todayFormat(calDate);
        if (eventDates[nDate] > -1)
         toolid = 't' + eventDates[nDate];
         var myele = new Array;   
         myele[0] = tds[r];
         var t = new Spry.Widget.Tooltip(toolid,myele,{offsetY:25});
    Spry.Data.Region.addObserver("tooltips", myObserver);
    The tooltips is a div region containing all my tooltips for the calendar and generated from my SpryData Events data
    <div id="tooltips" spry:region="Events">
            <div spry:repeat="Events" id="t{ds_RowNumber}" class="tooltipContent hide"> {Title} </div>
          </div>
    I generate a unique id for each tooltip that I can use with the tooltip widget when attaching the triggers from the calendar as above. It uses the spry data row number to achieve this.
    Hope this helps you with your highlighting and tooltips if you want them. Note I ignore my first two events for highlighting as their start and end dates spans years and just represent club stuff that happens every week. Otherwise initialise your i variable with var i = 0; in the loop.
    Just noticed if I use the calendar nav controls it drops the tooltips.  I'll need to add a YUI render event notifier to pick that up.
    Cheers
    Phil

  • I can't get today's date to show on my html pages with Javascript codes.

    I use javascript 1.2 codes to show up today's date on my HTML pages but it did not execute.
    Here is my code:
    <script language="Javascript">
    <!--
    document.write(displayDate());
    // -->
    </script>
    Please help! If you know how to get it to execute.
    Thank you.

    I don not know what displayDate() means
    But I am display current date and time with the code...
    <script language="Javascript">
    <!--
         document.write((new Date).toLocaleString());
    // -->
    </script>

  • How do I get my calendar to adapt to time zone change?

    My calendar is run in MS Outlook on my windows office computer and syncs via Exchange 2003 server to my iPhone.
    I live in Europe. I recently attended a business event in the States. All my appointments were in my Outllook calendar in local time. But when I got to the States and changed my iPhone to local time, all my appointments were shifted by 9 hours, this being the time difference.
    The only hack I could find to get them to display properly was to pretend my phone was still on European time and reset this manually to the local time in California. Only then did the appointments appear at the right time.
    Surely there must be a better way? Otherwise, what's the point of all the settings option for local time support?

    Was the objective to have the appointments and calendar show in Euro-time while in California with the time shifted +9 hours while the device time was on California time?  As  i understand it, Location services controls the device getting it's own time from the local cell infrastructure, and calendar time zone support would allow the calendar to be displayed in a time zone other than that physical time zone the device is  present in....everytime this question comes up I have to review these two kb's...they are not light reading
    http://support.apple.com/kb/HT4576
    http://support.apple.com/kb/HT4504

  • Get today's date minus 30 seconds

    How can I get the current date and time minus 30 seconds. The result shoulld be of date format.
    Thanks.

    You mean when you were answered 2 days ago on the same question you had to ask it again?
    http://forum.java.sun.com/thread.jspa?threadID=596493
    Thanks for wasting more answerers' time.

  • Iphone 5C setting appointments in GMT time zone, not my time zone

    Why is my iPhone 5C now recording my calendar appointments in GMT time, not my time zone. I started happening a few weeks ago. I just updated the iOS to version 8.1.2 and it is still happening. Any suggestions?

    See this thread, ongoing for several months: iOS 8 Calendar on iPhone showing GMT times for new events.

Maybe you are looking for

  • Numeric overflow with DBMS_CDC_PUBLISH.CREATE_CHANGE_TABLE

    Hello all- I'm running Oracle 9i on WinXP sp. 2. I'm trying to create a CDC table with the standard SYS package and am getting a numeric overflow error. The code I'm attempting to execute is this: BEGIN sys.dbms_cdc_publish.create_change_table( OWNER

  • Treemap Chart not showing on Server

    Hi, I ran into an "Unexpected error occurred; contact your system administrator" error when I try to use the Treemap in my Dashboard. The treemap looks fine in Design Studio, but when I run it locally or on the server, the error occurs. The error mes

  • Re: Having trouble activating your Creative Cloud subscription in trial applications?

    I get an "Internet connection required for subscriptions" error.  And yes, I'm connected to the internet, but I am behind a pretty mean firewall.  Product Updates can see my proxy and download, but Activation can't?

  • Reciving error code 205

    I am trying to up dater but can't recive error code 205

  • All My Files now empty?

    From Day 1 until yesterday, I had a ton of files listed in All My Files section of Finder window. After doing the 10.7.1 update yesterday, All My Files is now totally empty. Nothing is acting or behaving any differently than before, and anything that