Formatting a date that should be GMT

Hi,
From an API I get time in milliseconds and I put that value into a java.util.Date object. The time is in UTC and my local time zone is EST. I want to display this value, adjusted to the user specified time zone, but I can't get how to tell the Calandar class that the time I giving it is UTC and not EST, so it is adjusting it wrong. Also, I can't assume what the local timezone will be. So far my code looks like:
   // date (Date), gmtOffset (int) and format (String) are method inputs
  int offsetAdjusted = gmtOffset * (3600000);
  SimpleTimeZone tz = new SimpleTimeZone(offsetAdjusted,gmtOffset+":00");
  Calendar cal = Calendar.getInstance( );
  cal.setTimeZone(tz);
  SimpleDateFormat dateFormat = new SimpleDateFormat(format);
  dateFormat.setCalendar(cal);
  System.out.println(dateFormat.format(date) );any help would be very much appreciated.

import java.awt.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
public class ShowingGmtTime
    public static void main(String[] args)
        String[] ids = TimeZone.getAvailableIDs(+8*60*60*1000);
        for(int i = 0; i < ids.length; i++)
            System.out.println(ids);
DateFormat df = new SimpleDateFormat("HHmm ddMMMyyyy");
Date now = new Date();
System.out.println("local time = " + df.format(now));
TimeZone gmtZone = TimeZone.getTimeZone("GMT");
df.setTimeZone(gmtZone);
System.out.println("GMT time = " + df.format(now));

Similar Messages

  • What are the Master data that should be uploaded for Go live

    Can any one tell me what are the SD master data that should be uploaded during GO live

    Hi Prem,
    SD Master data includes:
    - Customer Master data
    - Material Master data
    - Customer-Material Info records
    - Enterprise Structure info (Dist Channels,Divisions etc)
    - Condition Master Data in Pricing.
    I believe, all these need to be uploaded during GO Live.
    regards,
    Raj

  • How to have a web-based interface for Lumira that also performs Ad-Hoc visualizations on data that should be loaded live from HANA.

    How to have a web-based interface for Lumira that also performs Ad-Hoc visualizations on data that should be loaded live from HANA. I have another tool that puts data into HANA, So don't want to reload this new data into Lumira every time I want to run a report.
    so do i  have the ability to create polished ad hoc dashboards, reports, infographics and storyboards Apart from Ad-Hoc reports, I also need a dashboard with some fixed reports that update with the live data.
    So please suggest me to accomplish this task.
    Thanks and regards
    Shashi kiran

    Please have a look at Ludek's document here which contains links: SAP Lumira Family Supported Versions Matrix
    Ludek has also attached the PAM's as zipped files; Lumira comes in many flavors so I encourage you to research options
    Also see this "HANA Live" document: [SAP HANA Academy] Visualized: Lumira & HANA

  • Formatting a date that is inserted into a text object

    The on-line documentation for inserting a date into a form letter instructs a user to insert a Print Date into a text object.  To format the date, the user is instructed to double-click on the date object and then right click and select Format {Print Date} from the menu.
    This works when using Crystal Reports 2008 without any service packs.
    However, after installing SP1, this feature no longer works.  The Format {Print Date} is grayed out and not available for selection.
    I am using VISTA Enterprise.
    Are there any reasonable reasons why this functionality was removed with SP1.

    You have a brilliant work around.  Thanks!
    However, it is still a work around.
    I hope someone within the Crystal Reports organization sees this post and either provides an explaination as to why SP1 does not allow you to directly edit a field or that someone realizes that this is a bug and starts the process of providing a fix.
    By the way, I duplicated the problem on both VISTA and XP machines.

  • How to compare two dates that should not exceed morethan 3 years

    hi all,
    can you please tell me how to compare two dates( basically dates are string type)
    that should not exceed more than 3 years? in JAVASCRIPT
    Thanks in Advance.

    This is not a JavaScript forum.
    [*Google* JavaScript Forum|http://www.google.co.uk/search?q=JavaScript+Forum&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a]
    Good luck.

  • How to change the format of date that i am displaying in a table

    Hi everyone,
    I have a table in my jsp page that display records from a table and want to format a field that is the date to "dd-MMM-yyyy"...
    How can i do that please help me.
    I am using EJB 3.0
    Regards
    Lutchumaya
    Message was edited by:
    Lutchumaya

    Hi Lutchumaya,
    If it's only for display in a table, you can use <f:convertDateTime>.
    For example:
    <af:column sortable="false">
    <af:outputText value="#{row.DateEnd}">
    <f:convertDateTime pattern="#{SystemState.dateFormat}"/>
    </af:outputText>
    </af:column>
    And the dateFormat is being set in a backingbean.
    public String setDateFormat() {
    return "dd-MMM-yyyy";
    I hope this helps.
    Luc Bors

  • Is there a way to format text data that has been persisted?

    I am persisting five lines of numeric data in my app.  Each persisted line of data saves and returns perfectly after a ro-boot, except for the text size and color.
    To be clear : If I save 199.55, that is what appears after a device re-boot.  The 'formatting' I am having issues with it the font size and color.
    For some reason, the font sizes have changed and some of the font colors are incorrect.
    Is there a way to correct this or prevent it from happening?
    Thanks.

    If you are saying that I can only save text data, I can accept that.
    But, why then does my saved data come back in its own colors and various font sizes?
    Thanks for your post.

  • HT2480 When I type a text message the name it puts as "to" does not match the name that I have on my contact. i.e. shows John and Jane Doe when contact just has Jane Doe. Is there some old data that should be cleared? Can I stop the auto selection?

    See question above

    Do you have Facebook contacts turned on? It may be at some time you got an email message from them and that is the way they have their return address set. All previously used addresses are in a cache on the phone and the only way to clear that is to restore the phone as a new device, which deletes all data from the phone. You cannot restore from a backup because the information is in that and will just be put back on the phone.

  • Normally if anyone buys an apple product (mac) , it comes with a built-in-apps that should be considered ( built in ) , Then why when the mac faces a mistake or an error that forces it to format , these apps don't show up ? etc : iMovie , garageband

    normally if anyone buys an apple product with a specific model (mac) , it comes with a built-in-apps that should be considered ( built in ) , Then why when the mac faces a mistake or an error that forces it to format , these apps don't show up ? etc : iMovie , garageband ...
    considered it should be '' BUILT IN APPS '' ??
    So does it really make sense that i should buy these apps again after i already payed an extra amount of money in the first place to get a model that includes them ??
    after formatting my mac these apps should be there like its a whole new device that i opened !!!
    I hope anyone with any useful information can share his thoughts or help with further steps .

    Downloading past purchases from the App Store, iBookstore, and iTunes Store   

  • Formatting output so that data repeated between rows is not shown

    Hi Everyone,
    Here is a snippet of some sample data from a report that I have just written -
    Notice above that the 'Item Code', 'Item Description', and 'Order Qty' all repeat for rows 2 and 3.
    I would like to remove the repeated data (and ideally replace it with 'empty' cells), similar to the snippet below -
    I am connecting to an MS SQL Server 2008 R2 database, and therefore I have come to believe I cannot use the IIF(...) function, as detailed in
    this link.
    How can I go about formatting the data as indicated above?
    Any help will be greatly appreciated.
    Kind Regards,
    David

    Here is my initial attempt where only the Seq column is shown.
    select *
    from
    select ROW_NUMBER()
    over
    partition by td.ItemCode , td.Dscription, td.Quantity, titm.OnOrder, th.CardCode, th.CardName, th.DocNum, tsp.SlpName, twhs.WhsCode
    order by td.ItemCode
    as 'Sequence No.'
    from AU.dbo.RDR1 td
    left outer join AU.dbo.ORDR th on th.DocEntry = td.DocEntry
    left outer join AU.dbo.OITM titm on titm.ItemCode = td.ItemCode
    left outer join AU.dbo.OITW twhs on twhs.ItemCode = td.ItemCode
    left outer join AU.dbo.OSLP tsp on tsp.SlpCode = td.SlpCode
    left outer join A1Warehouse.dbo.BINLOCAT tbloc on tbloc.PRODUCT = td.ItemCode collate SQL_Latin1_General_CP850_CI_AS
    where
    td.LineStatus = 'O' and td.ItemCode = 'DR1124' and twhs.WhsCode like @whCode
    ) as ResultsGroup
    And then I attempted to 'refine' it further...
    select
    case when Seq = 1 then td.ItemCode else '' end as 'Item Code',
    case when Seq = 1 then td.Dscription else '' end as 'Item Description',
    case when Seq = 1 then td.Quantity else '' end as 'Order Qty',
    case when Seq = 1 then titm.OnOrder else '' end as 'PO Qty',
    case when Seq = 1 then th.CardCode else '' end as 'BP Code',
    case when Seq = 1 then th.CardName else '' end as 'BP Name',
    case when Seq = 1 then th.DocNum else '' end as 'Sales Order Number',
    case when Seq = 1 then tsp.SlpName else '' end as 'Sales Person',
    case when Seq = 1 then twhs.WhsCode else '' end as 'Whs Code',
    isnull(tbloc.BINLABEL, '') as 'BIN Label',
    isnull(cast(tbloc.QUANTITY as nvarchar(20)), '') as 'BIN Qty'
    from
    select ROW_NUMBER()
    over
    partition by td.ItemCode , td.Dscription, td.Quantity, titm.OnOrder, th.CardCode, th.CardName, th.DocNum, tsp.SlpName, twhs.WhsCode
    order by td.ItemCode
    as Seq
    from AU.dbo.RDR1 td
    left outer join AU.dbo.ORDR th on th.DocEntry = td.DocEntry
    left outer join AU.dbo.OITM titm on titm.ItemCode = td.ItemCode
    left outer join AU.dbo.OITW twhs on twhs.ItemCode = td.ItemCode
    left outer join AU.dbo.OSLP tsp on tsp.SlpCode = td.SlpCode
    left outer join A1Warehouse.dbo.BINLOCAT tbloc on tbloc.PRODUCT = td.ItemCode collate SQL_Latin1_General_CP850_CI_AS
    where
    td.LineStatus = 'O' and td.ItemCode = 'DR1124' and twhs.WhsCode like @whCode
    ) as ResultsGroup
    Here are the error messages that I get from running the above code snippet.
    The multi-part identifier error message
    I am sure that I have made several errors, however I am new to MS SQL programming so please be patient with me.
    try like below
    select
    case when Seq = 1 then ItemCode else '' end as 'Item Code',
    case when Seq = 1 then Dscription else '' end as 'Item Description',
    case when Seq = 1 then Quantity else '' end as 'Order Qty',
    case when Seq = 1 then OnOrder else '' end as 'PO Qty',
    case when Seq = 1 then CardCode else '' end as 'BP Code',
    case when Seq = 1 then CardName else '' end as 'BP Name',
    case when Seq = 1 then DocNum else '' end as 'Sales Order Number',
    case when Seq = 1 then SlpName else '' end as 'Sales Person',
    case when Seq = 1 then WhsCode else '' end as 'Whs Code',
    isnull(BINLABEL, '') as 'BIN Label',
    isnull(cast(QUANTITY as nvarchar(20)), '') as 'BIN Qty'
    from
    select ROW_NUMBER()
    over
    partition by td.ItemCode , td.Dscription, td.Quantity, titm.OnOrder, th.CardCode, th.CardName, th.DocNum, tsp.SlpName, twhs.WhsCode
    order by td.ItemCode
    as Seq,
    td.ItemCode,
    td.Dscription ,
    td.Quantity ,
    titm.OnOrder ,
    th.CardCode ,
    th.CardName,
    th.DocNum,
    tsp.SlpName,
    twhs.WhsCode,
    tbloc.BINLABEL,
    tbloc.QUANTITY
    from AU.dbo.RDR1 td
    left outer join AU.dbo.ORDR th on th.DocEntry = td.DocEntry
    left outer join AU.dbo.OITM titm on titm.ItemCode = td.ItemCode
    left outer join AU.dbo.OITW twhs on twhs.ItemCode = td.ItemCode
    left outer join AU.dbo.OSLP tsp on tsp.SlpCode = td.SlpCode
    left outer join A1Warehouse.dbo.BINLOCAT tbloc on tbloc.PRODUCT = td.ItemCode collate SQL_Latin1_General_CP850_CI_AS
    where
    td.LineStatus = 'O' and td.ItemCode = 'DR1124' and twhs.WhsCode like @whCode
    ) as ResultsGroup
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • I went to apple store sat 2.4 and was told that to get verizon not to charge me for the next cycle i should cancel the service .i lost my data that i pais

    i went to apple store sat 2.4 and was told that to get verizon not to charge me for the next cycle i should cancel the service .i lost my data that i paid for on 2.1.how do i restore my service that i paid for

    Go back to the store and discuss this with the person that gave you the advice.

  • Problem in converting the String to Date with time zone GMT

    Hi,
    When I tried to convert the string 12/05/2009 to Date, the time zone is set to BST.On the other hand, for the date 12/12/2009, the time zone is set to GMT. What should I do to get the time zone as GMT all the time.?
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    String dateString = "12/05/2009";
    System.out.println(myDate.toString());

    I think you are all missing the point. java.util.Date objects always alway always store the date as the number of milliseconds since 1/1/1970 UTC so the only TimeZone they have its the implicit UTC. When you use the Date.toString() method the toString() method gets the default time zone from your environment and formats the data accordingly. This means that the same Date object will, by default, produce a different result for France and Australia and the US.
    So, if you have the date "12/5/2009" as a String then to convert it to a java.util.Date you must specify what TimeZone is implied. If it is your system time zone then you can just create a SimpleDateFormat object with the correct format and then use the parse() method to create the java.util.Date object and this will automatically be converted to UTC. If the date String represents some other time zone then you must explicitly set the time zone of the SimpleDateFormat object before parsing the string.
    The same approach applies when converting a java.util.Date object to a String. If you want anything other than your system time zone then you must explicitly tell the SimpleDateFormat what time zone you want the result formatted for.

  • Stop Numbers form auto-formatting imported data

    I use a program to track my time, and it exports as a tab-delimited text file. This should be perfect, just import the data into a Numbers table and bada-bing, right?
    Unfortunately, Numbers is taking it upon itself to auto-format the data as it comes in. For example, there are 2 columns in the report that get auto-formatted. The event start column is exported in the form: dd/mm/yyyy hh:mm, and this is handled fine. The duration column is exported in the form: hh:mm, yet is auto formatted as dd/mm/yyyy hh:mm by Numbers.
    Does anyone know a way to stop Numbers from doing this? My only quick workaround is to import the report in Excel first, then open the Excel xsls file in Numbers (and at that point, why bother using Numbers at all?).
    HELP!

    No need to use two applications!
    --[SCRIPT dateTime2duration.app]
    Enregistrer le script en tant que Script, Application ou Progiciel : dateTime2duration.xxx
    déplacer l'application créée dans le dossier
    <VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
    Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
    Sélectionner les cellules à convertir
    menu Scripts > Numbers > dateTime2duration
    Le script insère les durées correspondantes.
    --=====
    L'aide du Finder explique:
    L'Utilitaire AppleScript permet d'activer le Menu des scripts :
    Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case "Afficher le menu des scripts dans la barre de menus".
    +++++++
    Save the script as a Script, an Application or an Application Bundle: dateTime2duration.xxx
    Move the newly created application into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
    Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
    Select cells to convert.
    menu Scripts > Numbers > dateTime2durationNumbers
    The script insert the corresponding durations.
    --=====
    The Finder's Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the "Show Script Menu in menu bar" checkbox.
    --=====
    Yvan KOENIG (Vallauris FRANCE)
    14 mai 2009
    --=====
    on run
    set {dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
    set localOffset to (time to GMT)
    tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
    repeat with x from colNum1 to colNum2
    tell column x
    repeat with y from rowNum1 to rowNum2
    try
    set theDate to (value of cell y)
    if class of theDate is date then
    tell (theDate - localOffset)
    set {hh, mm, ss} to {(its hours) as text, its minutes, its seconds}
    end tell
    set value of cell y to hh & "h" & mm & "m" & ss & "s"
    end if -- class…
    end try
    end repeat -- y
    end tell -- column x
    end repeat -- x
    end tell -- Numbers …
    end run
    --=====
    on getSelParams()
    local r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2
    set {d_Name, s_Name, t_Name, r_Name} to my getSelection()
    if r_Name is missing value then
    if my parleAnglais() then
    error "No selected cells"
    else
    error "Il n'y a pas de cellule sélectionnée !"
    end if
    end if
    set two_Names to my decoupe(r_Name, ":")
    set {row_Num1, col_Num1} to my decipher(item 1 of two_Names, d_Name, s_Name, t_Name)
    if item 2 of two_Names = item 1 of two_Names then
    set {row_Num2, col_Num2} to {row_Num1, col_Num1}
    else
    set {row_Num2, col_Num2} to my decipher(item 2 of two_Names, d_Name, s_Name, t_Name)
    end if
    return {d_Name, s_Name, t_Name, r_Name, row_Num1, col_Num1, row_Num2, col_Num2}
    end getSelParams
    --=====
    on decipher(n, d, s, t)
    tell application "Numbers" to tell document d to tell sheet s to tell table t to return {address of row of cell n, address of column of cell n}
    end decipher
    --=====
    set { d_Name, s_Name, t_Name, r_Name} to my getSelection()
    on getSelection()
    local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
    tell application "Numbers" to tell document 1
    repeat with i from 1 to the count of sheets
    tell sheet i
    set x to the count of tables
    if x > 0 then
    repeat with y from 1 to x
    try
    (selection range of table y) as text
    on error errMsg number errNum
    set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
    return {theDoc, theSheet, theTable, theRange}
    end try
    end repeat -- y
    end if -- x>0
    end tell -- sheet
    end repeat -- i
    end tell -- document
    return {missing value, missing value, missing value, missing value}
    end getSelection
    --=====
    on decoupe(t, d)
    local l
    set AppleScript's text item delimiters to d
    set l to text items of t
    set AppleScript's text item delimiters to ""
    return l
    end decoupe
    --=====
    on parleAnglais()
    local z
    try
    tell application "Numbers" to set z to localized string "Cancel"
    on error
    set z to "Cancel"
    end try
    return (z is not "Annuler")
    end parleAnglais
    --=====
    --[/SCRIPT]
    Yvan KOENIG (from FRANCE jeudi 14 mai 2009 14:01:29)

  • Convert String to Date and Format the Date Expression in SSRS

    Hi,
    I have a parameter used to select a month and year  string that looks like:    jun-2013
    I can convert it to a date, but what I want to do is,  when a user selects a particular month-year  (let's say "jun-2013")
    I  populate one text box with the date the user selected , and (the challenge Im having is)  I want to populate a text box next to the first text box with the month-year  2 months ahead.    So if the user selects 
    jun-2013   textbox A will show  jun-2013 
    and textbox B will show  aug-2013..
    I have tried:
    =Format(Format(CDate(Parameters!month.Value  ),  
    "MM-YYYY"  )+ 2  )   -- But this gives an error
    This returns the month in number format   like "8"    for august...
    =Format(Format(CDate(Parameters!month.Value  ), 
    "MM"  )+ 2  )
    What is the proper syntax to give me the result    in this format =  "aug-2013"  ???
    Thanks in advance.
    MC
    M Collier

    You can convert a string that represents a date to a date object using the util.scand JavaScript method, and then format a date object to a string representation using the util.printd method. For more information, see:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1254.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html
    In your case, the code would be something like:
    var sDate = "2013-01-10";
    // Convert string to date
    var oDate = util.scand("yyyy-mm-dd", sDate);
    // Convert date to new string
    var sDate2 = util.printd("mm/dd/yyyy", oDate);
    // Set a field value
    getField("date2").value = sDate2;
    The exact code you'd use depends on where you place the script and where you're getting the original date string, but this should get you started.

  • Formatting a date in XSLT

    I am working with an XSLT fragment in dreamweaver and all
    seems to be working fine except when it comes to the date field in
    the XML it is transforming. It looks like dreamweaver has no
    options in it for formatting a date. Looking on the web it appears
    that XSLT doesn't have a function for that except if you are
    running XSLT 2.0??
    my XML looks like
    <pubDate>Wed, 04 Apr 2007 04:00:00
    +0100</pubDate>
    Can anyone help me just show only this part, "Wed, 04 Apr
    2007"
    thanks
    chris

    >I am working with an XSLT fragment in dreamweaver and all
    seems to be
    >working
    > fine except when it comes to the date field in the XML
    it is transforming.
    > It
    > looks like dreamweaver has no options in it for
    formatting a date. Looking
    > on
    > the web it appears that XSLT doesn't have a function for
    that except if
    > you are
    > running XSLT 2.0??
    Correct.
    > my XML looks like
    > <pubDate>Wed, 04 Apr 2007 04:00:00
    +0100</pubDate>
    > Can anyone help me just show only this part, "Wed, 04
    Apr 2007"
    With XSLT, this should work:
    <xsl:value-of select="substring(pubDate,1,16)"
    order="descending" />
    The substring function variables are:
    substring(node, postition of start character in string, total
    number of
    characters to include)
    It's akin to a TRIM string statement in server-side
    programming languages.
    -Darrel

Maybe you are looking for