Convert date time local Timezone  to GMT

I need to get GMT time...
How to convert local time to GMT ?
     public static long getGMTNow()
         Calendar local = new GregorianCalendar();
         local.set(Calendar.HOUR_OF_DAY, 0);              
         local.set(Calendar.MINUTE, 0);
         local.set(Calendar.SECOND, 0);
         System.out.println(local.getTime());
         System.out.println(local.getTimeInMillis());
         Calendar gmtC = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
         gmtC.setTimeInMillis(local.getTimeInMillis());
         System.out.println(gmtC.getTime());
         return gmtC.getTimeInMillis();
     }Result :
Thu Feb 12 00:00:00 EST 2009
1234414800034
Thu Feb 12 00:00:00 EST 2009
1234414800034

Calendar gpsTime = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
         gpsTime.set(Calendar.HOUR_OF_DAY, 10);              
         gpsTime.set(Calendar.MINUTE, 0);
         gpsTime.set(Calendar.SECOND, 0);
         System.out.println("gpsTime: "+gpsTime.getTime());
         Calendar realtime= new GregorianCalendar();
         realtime.set(Calendar.HOUR_OF_DAY, 5);              
         realtime.set(Calendar.MINUTE, 0);
         realtime.set(Calendar.SECOND, 0);
         System.out.println("realtime: "+realtime.getTime());
         System.out.println("COMPARETO : "+ realtime.compareTo(gpsTime));
         long timediff = realtime.getTimeInMillis() - gpsTime.getTimeInMillis();
         System.out.println(timediff/1000 + " sec");RESULT :
gpsTime: Mon Feb 16 05:00:00 EST 2009
realtime: Mon Feb 16 05:00:00 EST 2009
COMPARETO : 1
0 secOk, I done my homework. getTime() will allways return local time so I need to set the GPS time to a GMT Calendar to get the right result.
Funny thing, look at the compareTo result....

Similar Messages

  • How to convert date-time according to the Time Zone the client

    Urgent! Help wanted!
    I extract a date-time field (which is GMT time) from the central database but I need to convert it accordding to the TimeZone of the user and also the so-called winter time and summer time in the local. Any one has any good solution?
    Thanks.

    Use a Calendar, Timezone and Locale objects like this,
    TimeZone tz = TimeZone.getTimeZone("Germany/Berlin");
    Calendar cal = Calendar.getInstance(tz, Locale.GERMAN);
    long date = 0; // assign your central database value to this variable
    cal.setTime(new Date(date));
    Now you can use the Calendar object 'cal' to retrieve the time according to the set locale and timezone.
    These objects provide tonnes of features for finding out timezones and day light savings times. So check out the APIs as well.
    I hope this helps you out.

  • How convert date/time from xml in xdp(Designer)?

    Hi, i want to convert date/time format from xml in Designer, date/time value in xml is NOT in common format YYYY-MM-DD (if is in a common format i can do this with pattern)
    I have a "DateTime" Field in Xdp can get from Xml date and time:
    In XML <DateTime>DD-MM-YYYY</DateTime> i want to convert in XDP in DateTime Field in "DD-April-YYYY"
    Can i do this?

    You can do this way..
    Bind the date field to your XML tag.
    Set the display pattern for the date field.
    In the initialize event of the date field place the following code.
    Set JavaScript as language.
    var dtStr = this.rawValue;
    var pos1=dtStr.indexOf("-");
    var pos2=dtStr.indexOf("-",pos1+1);
    var strMonth=dtStr.substring(0,pos1);
    var strDay=dtStr.substring(pos1+1,pos2);
    var strYear=dtStr.substring(pos2+1);
    //Assign the formatted value to the Date field.
    this.rawValue = strYear + "-" + strMonth + "-" + strDay;
    Thanks
    Srini

  • FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.

    HI EXPERTS,
         FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.
    PLS DO HELP.....

    Hiii gita
    we have another FM SPELL_AMOUNT
    regards
    Jaipal

  • Convert Data time stamp to Local Time

    Hello,
    I want to convert this input to local time EST.
    Input:12/8/2006 10:23:00.000000000 PM -06:00
    o/p: EST.Local Time

    Is the input a string? A timestamp? If so, which flavor of timestamp? Something else?
    Normally, you'd want to use a TIMESTAMP WITH LOCAL TIME ZONE data type for this sort of requirement, since it automatically converts data to the client's time zone. Assuming the input is a string and that the client's time zone is set to EST
      1  select cast(to_timestamp_tz( '12/8/2006 10:23:00.000000000 -06:00',
      2                               'MM/DD/YYYY HH24:MI:SS.FF TZH:TZM' )
      3                AS TIMESTAMP WITH LOCAL TIME ZONE)
      4*   from dual
    SCOTT @ nx102 JCAVE9420> /
    CAST(TO_TIMESTAMP_TZ('12/8/200610:23:00.000000000-06:00','MM/DD/YYYYHH24:MI
    08-DEC-06 11.23.00.000000 AM
    Elapsed: 00:00:00.01
    SCOTT @ nx102 JCAVE9420> Justin

  • How to convert date in one timezone to date in another timezone?

    Hi,
    I am building a web site which can be accessed by people across world in different timezones. I have a requirement to collect the data from the users in their respective timezones and convert it to the timezone in which the server is hosted before saving it. E.g. a user in "Kwajalein" timezone (GMT - 12) enters date as "10/23/2007 21:00", the time for the server which is hosted in indian timezone (GMT + 5.30) would be "10/24/2007 14:30". If I use the following program to convert the dates in these timezones it gives me wrong output.
    TimeZone tz = TimeZone.getTimeZone("Kwajalein");
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm");
    df.setTimeZone(tz);
    Date d = df.parse("10/23/2007 21:00");
    TimeZone tz1 = TimeZone.getTimeZone("Asia/Calcutta");
    df.setTimeZone(tz1);
    System.out.println("date in IST-->" + df.format(d));
    The output of this program is
    date in IST-->10/23/2007 14:30
    The formatter has changed the time component however it hasn't changed the date. It still appears as 23.
    Am I doing anything wrong here?
    Please pass your comments.
    Thanks,
    Shashi

    Please see the following link it may be helpfull to you
    1) http://forum.java.sun.com/thread.jspa?threadID=755558
    2) http://myhowto.org/java/36-all-about-locale-sensitive-time-processing-in-java/

  • Convert date/time to a value in second

    Hello,
    I want to convert a basic date time variable into a numeric one corresponding to the time (in second) passed since January,1,1970 in order to put it in a SQL statment as a criteria.
    Is someone able to help me ?
    Regards

    If you have an java.util.Date object you can call getTime() method on it. It will return milliseconds. Just divide it on 1000. Here is example code:
    java.util.Date date = new java.util.GregorianCalendar(2001, 7, 6).getTime();
    long seconds = date.getTime() / 1000;
    //Your code
    Best regards, Alex.

  • Convert date/time to Unix epoch

    I have thousands of date time stamps I would like to convert to Unix epoch ten-digit strings. That is, take some thing like:
    Dec 9, 2005 10:24 AM
    and convert to
    1234567890 (only in the correct unix epoch time)
    What formula can I use? I've found that this "=DATE(1970,1,1)+P2/86400" can convert a 10 string epoch time down to just a date correctly, but without time. But I need to go in the opposite direction, with the time included.
    Using Numbers 09 ver 2.0.5 (368)

    CP,
    An up-to-date Unix Time would be provided by:
    =DUR2SECONDS((NOW()-"1/1/1970"))
    A somewhat more robust form would be:
    =DUR2SECONDS(NOW()-DATE(1970,1,1))
    If the time to be converted is in Cell P2, the expression would be:
    =DUR2SECONDS(P2-DATE(1970,1,1))
    Jerry

  • IPod touch keeps changing the date, time, and timezone on its own

    Yesterday I noticed that the iPod was showing the wrong date, so I fixed it. I also checked the computer I was syncing to, but it had the correct date, time, etc. Now when I woke up the iPod today, the time, date, and timezone had all been changed again. Has anybody else had this problem, or know what I need to do to stop it? Thanks!

    When you sync the iPod, you have to sync it with a "new" iTunes window.
    Before you connect the iPod, exit out of iTunes, then reload it, and finally connect your iPod to it.
    I believe there was a software update that fixed this...

  • Convert date/time to HEX command and write to a bin file

    Hello,
    I have to do the following thing. I have the date/time string, let's say 08:45:23, 12.08.09, where the hour, the minutes, the seconds, the day, the month and the year represent hex number or in other words I have the following command:
    Byte 0 - Byte 5
    0x08; 0x45; 0x23; 0x12; 0x08; 0x09;
    Now I want to write this command in a binary file in order to send thefile later throught serial RS232 connection.
    Now, I am not sure whether I write the command in the binary file in the correct format. What I simply do is to write it as a string
    ("084523120809"). Is this the correct way. I guess no, because when transmitted it does not work as expected.
    How can I write this string as a HEX command in the binary file?
    Thanks for the replies in advance
    IG
    Message Edited by igurov on 08-12-2009 01:51 AM
    Attachments:
    1(2).JPG ‏39 KB

    Do you know the difference between decimal and hex values? It's not the same, that the whole point, and it's why it doesn't make sense. Decimal 32 is not the same as hex 32. These are two different values, even though they both have the digits "3" and "2". The hex value will be the same as the decimal value up to the value of 9. In your example the hour is 8. In decimal this is 8, in hex this is 8. The minutes is 45. That's decimal. In hex, this is 2D, not 45, as you claim in your example. Hex 45 is a completely different number (and a completely different "pattern").
    Attachments:
    time hex.vi ‏12 KB

  • Internationalization  issue : convert date/time to GMT/UTC

    We have our webservices running in websphere /oracle.There is this requirement to internationalize the application ...like
    a) language .....
    d)Internatiolization of time :
    For this requirment I am planning to do the following.Service request with date will be converted to GMT before it is stored in database and the response back will be converted from GMT back to the time zone of the requester and have the application server/database server configured to UTC time.Is this a good strategy or is there a better one.
    Thanks
    m

    Manjit wrote:
    Sabre,to confirm again...you are suggesting that there is even no need to change the oracle Date field from Date type to Timestamp.The only thing I really have to do is for display purpose convert/format the response date to the zone the request is coming from.Please let me know if I missed anything.The above statement is indefinite.
    Are you starting with a java.util.Date or perhaps a java.sql.Timestamp?
    Then you do NOT convert them. You display them. You use SimpleDateFormat for that. You do not concern yourself at all with timezones exception in terms of creating a SimpleDateFormat. And that is ONLY an issue if you are creating the string (display value) on a server. If you are doing that you will need the client to provide you with a timezone. There is no magic way to get that from the client. If a client app is doing the display the the client is running in a client VM and that VM will already have a display format that might be suitable.
    Conversely if you are receiving a timestamp value as a text value (say read it from a file) then you must convert that into a java.util.Date. You do that via SimpleDateFormat. The specifics of how you do that depends on the form of the text value.

  • Convert date/time to GMT format

    Hi,
    I want to convert my current system date to GMT format. the class java.util.Time/Calender have methods which help u to convert from GMT to local time.
    is there a method to convert from current System Date to GMT.
    tx in advance

    i found the answer to my earlier question from the postings. Now i need help with the format og the Date in GMT.
    i used the following code to get the GMT based on the system time
    Calendar here = Calendar.getInstance();
    int gmtoffset = here.get(Calendar.DST_OFFSET)
    + here.get(Calendar.ZONE_OFFSET);
    //to convert to GMT time
    Date GMTDate = new Date(System.currentTimeMillis() - gmtoffset);
    the result of exceuting the following code is
    GMT Date is Mon Aug 20 18:39:19 EDT 2001
    but i need the GMT time in this format
    20010820-18:39:40
    tx
    Namrata

  • How convert date with different timezone?

    HI,
    My problem is pretty simple. I have one Date and given another time zone (as a string), I want to have another date object with a different time zone. I used jodaTime. The code is as follows:
    DateTimeZone zone = DateTimeZone.forID("US/Eastern");
    DateTime parsedDateTime = DateTimeFormat.forPattern("mm/dd/yyyy").withZone(zone).parseDateTime(dstr);
    System.out.println(parsedDateTime.toString());
    System.out.println(parsedDateTime.toDate().toString());The output is:
    2008-02-14T00:00:00.000-05:00
    Thu Feb 14 11:00:00 GMT+06:00 2008
    This is quite weird. As is obvious from the output, datetime stores date in the correct timezone. but when converted it to date it applies the jvm's timezone. Why is it so? And why is this time conversion mad e so difficult by providing zillions of classes and methods such as Date, Calendar etc.

    amishera2006 wrote:
    HI,
    My problem is pretty simple. I have one Date and given another time zone (as a string), I want to have another date object with a different time zone. I used jodaTime. The code is as follows:
    DateTimeZone zone = DateTimeZone.forID("US/Eastern");
    DateTime parsedDateTime = DateTimeFormat.forPattern("mm/dd/yyyy").withZone(zone).parseDateTime(dstr);
    System.out.println(parsedDateTime.toString());
    System.out.println(parsedDateTime.toDate().toString());The output is:
    2008-02-14T00:00:00.000-05:00
    Thu Feb 14 11:00:00 GMT+06:00 2008
    This is quite weird. As is obvious from the output, datetime stores date in the correct timezone. but when converted it to date it applies the jvm's timezone. Why is it so? And why is this time conversion mad e so difficult by providing zillions of classes and methods such as Date, Calendar etc.for the first question, i can't help you
    but for the second one, i guess it's for historic reasons (no defined standard at the beginning lead to a big mess, the same way as with encoding issues)

  • PowerBI regional/localisation settings (date time format/timezone) - PowerPivot dax NOW() returning UTC date

    Can the regional settings be changed for PowerBI or are we stuck with UTC? Tried googling but the only hits for 'regional powerbi' relate to the portal being available in that region, not any kind of localisation configuration
    I have a workbook that is set to auto refresh. I've added a 'last refreshed' label to the front page, but when refreshed on PowerBI it shows the time in UTC (10.5 hrs off from where I am).
    I'm not a sharepoint person so will need steps and diagrams if it's a sharepoint config setting :)
    Jakub @ Adelaide, Australia Blog

    Hi Ed,
    I have a date dimension and I add a computed column to it. It's called RefreshDate. The code for the computed column is =NOW()
    I then use this column to show to the user when the model was last refreshed.
    Hi Greg, not really interested in workarounds at this time (i have another thread going for that & my data source is web apis, not a relational db with datetime functions) -
    this is more of a question of "is it possible to choose which timezone is used by the powerbi vertipaq engine for scheduled refreshes? yes/no"
    We are working in a single time zone, but the PowerBI vertipaq engine looks like it's lives in london.
    It shows the correct current time on the local user's PC when I (or a user) refreshes this model locally. It shows the UTC date (my time zone - 10.5 hrs) when the report is refreshed by powerbi.
    I have a workaround going in my report currently using powerquery to get the utc date and manually add 10.5 hrs + add a label to my report that states this is a fixed 10.5hr. This is a hack because we're in a daylight savings zone, so in a few months
    the tz will revert to +9.5hrs and i'll need to manually fix this again unless i'm able to set powerbi to use my time zone.
    The sharepoint guys here have changed every setting they know about in sharepoint online/o365 in regards to time zones and localisation. The date format and dates shown are correct for the 'web pages' part of powerbi (the refresh history, the formatting
    of the dates on the powerview reports etc), but the time zone used when powerbi executes the NOW() dax command appears to be set to UTC.
    Thanks
    Jakub @ Adelaide, Australia Blog

  • Convert Date Time field to Date & Time

    Post Author: Smita
    CA Forum: Crystal Reports
    I am new to Crystal XI  . I need to convert DateTime ("2007/04/04/04 09:49:05:00") format to Date and Time and then group a months data first by date and then by Time ( per Hour ).
    If someone can help ?
    Thanks

    Post Author: newcruser
    CA Forum: Crystal Reports
    Thanks
    This is easy...second group based on the second formula 'for each hour'.
    How you group by 15 minutes?.
    i want to group by every 15 minutes starting from 9 AM to 5 PM.
    First i need to create a time range and then use that time range to group?.  Or any other simple and best way to solve this?. Please help
    How to create time range from 9 AM to 5 PM?

Maybe you are looking for

  • Can I get total number of page in 'After Report' Trigger?

    Currently, I use the format trigger of a field in Margin. In the trigger, I use srw.get_page_num(page_num) to get the current page number and call a package procedure to update a record. For example, if the report has 10 pages, it will update 10 time

  • Entourage Works, But Web Pages Do Not Load

    I work at a school that has several MacBook's that were setup with the same disk image. One of them has stopped loading web pages (using both Firefox and Safari), but Entourage can still send and receive email without a problem (POP/SMTP). All other

  • Zen Neeon not work

    My zen neeon is stuck on the recharging screen. I've tried formatting, didn't do a thing. I downloaded the firmware update, but it wont install, it keeps losing the connection. Anyone have any ideas?

  • OWB steps

    do somebody have a document with detailed steps of how to design a datawarehouse set up using the owb. I don't have any idea about the Mappings and Transformations. Searched in net for documents, didn't find anything. So somebody help.

  • Event splitting issues

    Trying to split an event into multiple events and iPhoto has booted me out.  Anyone seen this before and know how to resolve