How to convert a datetime value to UTC (or GMT)

I have this problem.
The user should provide the following inputs:
- A date time value - i.e: 10 september 2006, 10:40 AM
- The world location to which that value refers - i.e.: Rome/Italy
I need as output, the UTC date time value:
- i.e: 10 september 2006, 8:40 AM
in this case it is two hours before because during summer time, the Italian timezone is GMT+2
And if the user enters:
- A date time value - i.e: 25 december 2006, 10:40 AM
- The world location to which that value refers - i.e.: Rome/Italy
The output should be: (UTC time)
- i.e: 25 december 2006, 9:40 AM
It only only one hour before because during winter, in italy the timezone is GMT+1
In few words I need that Java can do by itself all the calculations about the timezone and daylight saving around different places in the world, so that I can store in my DB the universal UTC time.
Can you suggest me some code or some good URLs?
Thanks in advance

I wrote this code, it works but I have still some issues.
          GregorianCalendar abroad = new GregorianCalendar(TimeZone.getTimeZone("Asia/Tokyo"));
          abroad.set(Calendar.YEAR, 2006);
          abroad.set(Calendar.MONTH, 11);
          abroad.set(Calendar.DATE, 25);
          abroad.set(Calendar.HOUR_OF_DAY, 1);
          abroad.set(Calendar.MINUTE, 0);
          abroad.set(Calendar.SECOND, 0);
          System.out.println(abroad.getTime());
        DateFormat df1 = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
          df1.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
          System.out.println(df1.format(abroad.getTime()));
        DateFormat df2 = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
          df2.setTimeZone(TimeZone.getTimeZone("America/New_York"));
          System.out.println(df2.format(abroad.getTime()));
        DateFormat df3 = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
          df3.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
          System.out.println(df3.format(abroad.getTime()));          It outputs:
Sun Dec 24 17:00:00 CET 2006
luned� 25 dicembre 2006 1.00.00 JST
domenica 24 dicembre 2006 11.00.00 EST
domenica 24 dicembre 2006 16.00.00 UTCIn few words this code is able to compute any date from a specific timezone, to other timezone.
My questions are:
- Why the first output is in english ? and the other are in italian? (my OS is italian) but I didn't changed the locale in the code, so I don't understand why it outputs english text.
- When I get the date value in other timezones, I just get a "string" computed by the "format(...)" method of the DateFormat class.
But I really need to get something "numeric" for every specific value: minutes, hours, day of the month, month, year. Because this class will be used outside java and I don't need a string but something that the user will have formatted in his choosen locale setting for its website. (i think that I was not good to explain this point, i hope that someone can understand)
However thank you all :)

Similar Messages

  • How to convert a string value to date

    Dear All,
    I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.
    but when i try to convert the variable to date value, I am getting the error as below.
    Please help me......
    PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
    PS C:\script> $passwordSetDate
    PasswordLastSet
    7/15/2014 8:17:24 PM
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    Cannot find an overload for "ParseExact" and the argument count: "3".
    At line:1 char:1
    + $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)

    Dear All,
    I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.
    but when i try to convert the variable to date value, I am getting the error as below.
    Please help me......
    PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
    PS C:\script> $passwordSetDate
    PasswordLastSet
    7/15/2014 8:17:24 PM
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    Cannot find an overload for "ParseExact" and the argument count: "3".
    At line:1 char:1
    + $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    In your post you ask how to convert a string value to a date.  The value returned from the Get-AdUser is already a date.  It does not need to be converted.
    Bill has sshown one way to convert a date to a string and there are other methods.  You need to clarify your question.
    If you are really trying ot convert strings to dates then you can start with this:
    [datetime]'01/21/1965 13:33:23'
    Most date strings aer autodetected by the class.
    ¯\_(ツ)_/¯

  • How to convert ResultSet's value to String

    Dear JDC's
    plz tell me how to convert ResultSet's value to String.
    kashif

    I want to read a whole array from a table into a String[]
    and then send it to another servlet before I forward it all to anther servlet with request.setParameter.....
    Any ideas how to solve it....that is how far I got so far:
    rs=pgresult("select count (answer) from answers where qid="+idnum);
                                                           numberofquestions = rs.getInt("mynumber");     
                                                           rs=pgresult("SELECT answer FROM answers WHERE qgroup="+qgroup);
                                                           allanswers = new String[numberofquestions];
                                                           allanswers = (String[])rs.getArray(1).getArray();     
                                                           req.setParameter("allanswers",allanswers);
                                                           RequestDispatcher dispatcher = req.getRequestDispatcher("editanswers");
                                                           dispatcher.forward(req,res);
    Tobi

  • How to convert a date value into week value?

    How to display the date value like '20010203'
    into the week number of the year 2001?
    When i type in the following sql
    select week(chg_time) from site;
    I got this error message
    ORA-00904: invalid column name

    use the to_char function, to format the date into a week number (then you might need to convert that to a number using to_number)
    select to_char( sysdate, 'WW') from dual`
    a description of datetime formats: http://download-west.oracle.com/otndoc/oracle9i/901_doc/server.901/a90125/sql_elements4.htm#48515

  • DateTime is stored as an int. How to convert to datetime format??

    According to the database, StartTime is stored as int: 471895438
    When Viewed in the software it comes out like this: 9/29/2010
    10:05:26 AM
    Any ideas on how to convert this using sql?
    -Tim

    I tried to play with some "reverse engineer" to get the convert value but I dont see the logic. since I dont find a pure date that fit the convert but maybe this will help:
    declare @I INT = 471895438
    declare @DT datetime = '20100929 10:05:26'
    select
    @DT
    ,DATEADD(MS, @I*(-1), @DT)
    ,DATEADD(SECOND, @I*(-1), @DT)
    --,DATEADD(MINUTE, @I*(-1), @DT) -- out of range
    (No column name) (No column name) (No column name)
    2010-09-29 10:05:26.000 2010-09-23 23:00:30.563 1995-10-16 16:01:28.000
    by those result I guess that it is in MINUTE or SECOND
    and according to those result i will need to guess that one of those convert may work for the OP:
    SELECT DATEADD(MILLISECOND, @I, '2010-09-23 23:00:30.563')
    SELECT DATEADD(SECOND, @I, '1995-10-16 16:01:28.000')
    * I tried to use datetime2 as well and check the result for microsecond and nanosecond but the solution was not better and look like 2010-09-29 10:05:25.5281046, 2010-09-29 09:57:34.1045620
    ** This is really strange if someone use a value like 2010-09-23 23:00:30.563 as a base time, and even the base value 1995-10-16 16:01:28.000 then it look strange! but maybe this is the time that the developer born or some other specific time that fits his
    needs :-)
    ** I used my birthday date (but never not a min time), several times in application that I developed as a base time :-)
    [Personal Site] [Blog] [Facebook]

  • How to convert the character value to currency/numeric

    Hi,
    See the sample code here
    data: v_qtr_field(7).
    data: w_low_limit like glt0-kslvt,
          w_amount like glt0-hslvt.
    w_low_limit = 02.
    w_max_period = 3.
    concatenate 'HSL' w_low_limit into v_qtr_field.
    *comment
    *I am looking for a field formation thru above code like in GLT0 table like HSL02,HSL03 *etc based on the value user entered in the selection *screen
    DO w_max_period TIMES
      VARYING w_amount FROM v_qtr_field NEXT v_qtr_field + 1.
       t_trans_values-dmbe2 = t_trans_values-dmbe2 + w_amount.
      ENDDO.
    I am facing problem in the Do loop as it wont allows multiple data types. can you suggest me how to convert the v_qtr_field whose data type is character to currency?

    Hi,
    Please check this code .
    PERFORM write_currency
                  USING buf_anla-urwrt t_dates-waers t_txw_anla-urwrt.
    *       FORM WRITE_CURRENCY                                           *
    *       convert currency amount to string                             *
    *       - use decimal point                                           *
    *       - remove separator characters                                 *
    *  -->  P_AMOUNT                                                      *
    *  -->  P_CURRENCY_UNIT                                               *
    *  -->  P_STRING                                                      *
    FORM WRITE_CURRENCY
         USING P_AMOUNT        TYPE P
               P_CURRENCY_UNIT LIKE TCURC-WAERS
               P_STRING        TYPE C.
      DATA: DEC2POINT(2) TYPE C VALUE ',.'.
    * convert separator to decimal point
      WRITE P_AMOUNT TO P_STRING CURRENCY P_CURRENCY_UNIT
            NO-GROUPING
            NO-SIGN
            LEFT-JUSTIFIED.
      TRANSLATE P_STRING USING DEC2POINT.
    * put minus sign before number
      IF p_amount < 0.
        SHIFT P_STRING RIGHT.
        P_STRING(1) = '-'.
      ENDIF.
    ENDFORM.
    <i>Hope This Info Helps YOU.</i>
    Regards,
    Lakshmi

  • How to convert some row values in columns

    Hello guys,
    I'm using Oracle 10g in a windows platform, I have the following data:
    with test as
    select '000-ME-001' tag_number, 'Capacity 150' tag_details1, '000-TS-M-226' tag_details2 from dual union all
    select '000-ME-001' tag_number, 'Capacity 250' tag_details1, '000-TS-M-227' tag_details2 from dual union all
    select '000-ME-001' tag_number, 'Capacity 350' tag_details1, '000-TS-M-228' tag_details2 from dual union all
    select '000-ME-002' tag_number, 'Capacity 150' tag_details1, '000-TS-M-226' tag_details2 from dual union all
    select '000-ME-002' tag_number, 'Capacity 250' tag_details1, '000-TS-M-227' tag_details2 from dual union all
    select '000-ME-002' tag_number, 'Capacity 350' tag_details1, '000-TS-M-228' tag_details2 from dual union all
    select '000-ME-003' tag_number, 'Capacity 150' tag_details1, '000-TS-M-226' tag_details2 from dual union all
    select '000-ME-003' tag_number, 'Capacity 250' tag_details1, '000-TS-M-227' tag_details2 from dual union all
    select '000-ME-003' tag_number, 'Capacity 350' tag_details1, '' tag_details2 from dual
    )How can I covert the values of tag_details1 as column name to achieve this result:
    tag_number     Capacity 150     Capacity 250     Capacity 350
    000-ME-001     000-TS-M-226     000-TS-M-227     000-TS-M-228
    000-ME-002     000-TS-M-226     000-TS-M-227     000-TS-M-228
    000-ME-003     000-TS-M-226     000-TS-M-227Hope you can help me, best regards.

    select tag_number
         , max (decode (tag_details1, 'Capacity 150', tag_details2))
         , max (decode (tag_details1, 'Capacity 250', tag_details2))
         , max (decode (tag_details1, 'Capacity 350', tag_details2))
      from test
    group by tag_numberas in
    SQL> with test as
      2  (
      3  select '000-ME-001' tag_number, 'Capacity 150' tag_details1, '000-TS-M-226' tag_details2 from dual union all
      4  select '000-ME-001' tag_number, 'Capacity 250' tag_details1, '000-TS-M-227' tag_details2 from dual union all
      5  select '000-ME-001' tag_number, 'Capacity 350' tag_details1, '000-TS-M-228' tag_details2 from dual union all
      6  select '000-ME-002' tag_number, 'Capacity 150' tag_details1, '000-TS-M-226' tag_details2 from dual union all
      7  select '000-ME-002' tag_number, 'Capacity 250' tag_details1, '000-TS-M-227' tag_details2 from dual union all
      8  select '000-ME-002' tag_number, 'Capacity 350' tag_details1, '000-TS-M-228' tag_details2 from dual union all
      9  select '000-ME-003' tag_number, 'Capacity 150' tag_details1, '000-TS-M-226' tag_details2 from dual union all
    10  select '000-ME-003' tag_number, 'Capacity 250' tag_details1, '000-TS-M-227' tag_details2 from dual union all
    11  select '000-ME-003' tag_number, 'Capacity 350' tag_details1, '' tag_details2 from dual
    12  )
    13  select tag_number
    14       , max (decode (tag_details1, 'Capacity 150', tag_details2))
    15       , max (decode (tag_details1, 'Capacity 250', tag_details2))
    16       , max (decode (tag_details1, 'Capacity 350', tag_details2))
    17    from test
    18   group by tag_number
    19  /
    TAG_NUMBER MAX(DECODE(T MAX(DECODE(T MAX(DECODE(T
    000-ME-002 000-TS-M-226 000-TS-M-227 000-TS-M-228
    000-ME-001 000-TS-M-226 000-TS-M-227 000-TS-M-228
    000-ME-003 000-TS-M-226 000-TS-M-227Edited by: Alex Nuijten on Jun 3, 2009 4:03 PM

  • How to convert from Datetime to number?

    chg_date_time
    40265.492
    SELECT c.chg_date_time, TO_DATE('01011900','DDMMYYYY')+CHG_DATE_TIME FROM CHNGHIST C
    After execute:
    30/03/2010 11:48:29
    In the above query, we convert number to datetime.
    Now I want to convert from Datetime to number.
    i.e., 30/03/2010 11:48:29 = ? (40265.492)
    Thanks
    Nihar

    Hello,
    This would do it :SQL> select to_date('30/03/2010 11:48:29','dd/mm/yyyy hh24:mi:ss') - TO_DATE('01011900','DDMMYYYY') nmbr from dual;
          NMBR
    40265,492
    1 row selected.

  • How to Convert a HEX value to CHAR value...Unicode Issue...

    Hi,
    How can I convert HEX value to CHAR value.
    The Code in <b>non Unicode</b> system is:
    DATA: t_text LIKE tline OCCURS 0 WITH HEADER LINE.
    constants:   c_hex_20a5(2) TYPE x            VALUE '20A5'.
    t_text-tdline = 'seller of the item so listed.  A legend of the Seller Code(s) is as'.
          TRANSLATE t_text-tdline USING c_hex_20a5.
    The same code give error in <b>Uni-Code</b> system:
    <b>error is "c_hex_20a5 must be an character type object (C, N, D, T or String type)."</b>
    If anyone know, what is the solution, please let me know.
    Thanks!
    Puneet.

    Hi,
    Try declaring the Hex chars using the ABAP char utilities. This is just a sample piece of code on how to declare and use:
    CLASS cl_abap_char_utilities DEFINITION LOAD.
    DATA:  ws_lf TYPE c VALUE cl_abap_char_utilities=>cr_lf.
    data:    c_newline           TYPE x VALUE '0D'.  [ it is zero D, for carriage return ]
    ws_lf = c_newline.
        CONCATENATE it_tab-maktx
                    ws_lf
                    ws_template
                    INTO it_notificatn-template.
    Hope this helps...
    Regards
    Subramanian

  • How to convert a measure value to null when the actual measure value is 0

    Hello Gurus,
    I have year, products, measure 1, measure 2, measure 3. I am added three products into one category by using bin in the analysis i am getting zeros for some of the measure cells when it should be null values, because the actual measure values are null for indivudual product. How can i convert that 0's to null. Please advise.
    Thanks,
    RC

    To answer your immediate question, you can write this:
    CASE WHEN table.column = 0 THEN NULL ELSE table.column END
    Remember though, that any aggregations done on a record that is NULL will not yield a sum. That is why the usual case is to convert NULLs to 0s. But that may not be a concern for what you are doing. Good luck!

  • How to convert multiple string values in a single row from nvarchar to int

    suppose I have a table like below.all these values are in nvarchar. How would I find the minimum year from START_DATE??
    PRODUCT_CODE 
    PRODUCT_DESC
    START_DATE
    P00002933
    VITAMINE C
    2005,2000,2011,2001,2002
    P00003087
    BIOFENAC
    2011,2009,2006,2007,2004,2005
    P00000155
    AMOXYPEN
    2006,2007,2008,2009,0000,2001
    P00002325
    SAHHA FARINE
    2008,2003,2002,2001,2009
    P00005666
    AMOXYPEN
    2007,2008,2006,2009,0000,2001

    Create the split function:
    CREATE FUNCTION Split (
    @InputString VARCHAR(8000),
    @Delimiter VARCHAR(50)
    RETURNS @Items TABLE (
    Item VARCHAR(8000)
    AS
    BEGIN
    IF @Delimiter = ' '
    BEGIN
    SET @Delimiter = ','
    SET @InputString = REPLACE(@InputString, ' ', @Delimiter)
    END
    IF (@Delimiter IS NULL OR @Delimiter = '')
    SET @Delimiter = ','
    --INSERT INTO @Items VALUES (@Delimiter) -- Diagnostic
    --INSERT INTO @Items VALUES (@InputString) -- Diagnostic
    DECLARE @Item VARCHAR(8000)
    DECLARE @ItemList VARCHAR(8000)
    DECLARE @DelimIndex INT
    SET @ItemList = @InputString
    SET @DelimIndex = CHARINDEX(@Delimiter, @ItemList, 0)
    WHILE (@DelimIndex != 0)
    BEGIN
    SET @Item = SUBSTRING(@ItemList, 0, @DelimIndex)
    INSERT INTO @Items VALUES (@Item)
    -- Set @ItemList = @ItemList minus one less item
    SET @ItemList = SUBSTRING(@ItemList, @DelimIndex+1, LEN(@ItemList)-@DelimIndex)
    SET @DelimIndex = CHARINDEX(@Delimiter, @ItemList, 0)
    END -- End WHILE
    IF @Item IS NOT NULL -- At least one delimiter was encountered in @InputString
    BEGIN
    SET @Item = @ItemList
    INSERT INTO @Items VALUES (@Item)
    END
    -- No delimiters were encountered in @InputString, so just return @InputString
    ELSE INSERT INTO @Items VALUES (@InputString)
    RETURN
    END -- End Function
    GO
    Use the below script:
    create table Table1 (Product_Code varchar(50),Product_Desc varchar(10),sStart_date varchar(MAX))
    Insert into Table1 Values('P00002933','VITAMINE C','2005,2000,2011,2001,2002'),
    ('P00003087','BIOFENAC','2011,2009,2006,2007,2004,2005')
    Select Product_Code,Product_Desc ,MIN(Item) Minstart_date
    From Table1 A
    Cross apply Split(A.sStart_date,',') B
    Group by Product_Code,Product_Desc
    Drop table Table1

  • How to set Default DateTime values in Crystal Reports 2008

    Hi All,
    I'm using Crystal Reports 2008. I have two fields FromDate and ToDate in reports. While running report, FromDate field should be displayed with CurrentDate + 00:00:00 in the UI and for ToDate it should be displayed with CurrentDate + 23:59:59 format.
    I have tried the below things, But still I want to set CurrentDate + 00:00:00 time in DateTime field.
    "In CR 2008 you would set the time portion to 00:00:00 in this way:
    1) Edit the date/time parameter and look for the 'Default Value' option; it would be blank
    2) Set this to 00:00:00
    This would default the calendar to 12/30/1899 00:00:00. The only worry here is, when you click on the calendar icon you would be presented with the calendar for the year 1899 and it is painstaking to scroll all the way to the current year."
    I found one solution in SAP forum and I have added the below lines in Record Selection formula,
    {@FromDate} = date(@CurrentDate)+time(00,00,00)
    {@ToDate} = date(@CurrentDate)+time(23,59,59)
    When I run the report, I still getting the empty values in the input parameters screen.
    Am I missing anything? Kindly help
    Thanks,
    Ramesh Kumar G.

    See the following for samples:
    Java (Crystal Reports for Eclipse) SDK - Business Intelligence (BusinessObjects) - SCN Wiki
    BusinessObjects Enterprise / SAP BusinessObjects Business Intelligence Platform 4.x Java SDK Applications
    Business Objects / BI Unmanaged Java RAS SDK Sample Applications
    Developer Help Files:
    Crystal Reports SDK
    - Ludek
    Senior Support Engineer AGS Product Support, Global Support Center Canada
    Follow us on Twitter

  • How to convert a row value in CSV file to column value

    Hi
    We have one requirement where we have to show the row value to column level value
    for Example:
    Source file will be in below format
    Component Name :101
    **Batch #     **100% Mod     200% Mod      300% Mod      400% Mod     Tensile     Elongation     Thickness*
    8584-17     498     1211     1986     2601     3133 523     0.088
    Output Format has to be:
    **Batch #     **100% Mod     200% Mod      300% Mod      400% Mod     Tensile     Elongation     Thickness Component name*
    8584-17     498     1211     1986     2601     3133 523     0.088 101
    How can we achieve this using shell/Perl script

    .

  • How to convert pixel Measurment values to real world cordinate systems ( 2D & 3D)

    Hello  All
    I am very new to Image processing and I stuck in a position where i have to convert the pixel measurement value in the real world X,Y,Z  coordinates, and after then that value can be send to the robot arm.
    For more understanding i have attached the image of my VI and also the Labview VI, you can also suggest if something more is missing then what i already did
    I need help to solve this problem, as i already mentioned i am very new to image processing so answer in a simple explanations would be appreciated
    Thanks in Advance
    Attachments:
    Object_detection_Pixel.vi ‏48 KB

    Hello,
    I would like to help you with this topic.
    I have one question: have you tried to run the VI with highlight mode or with probes to see what happens step by step?
    Concerning the broken wire, as far as I can see it, its just the dimensions of the output array which does not fit.
    The data is an array of the dimension 2 but you connected an array with dimension 1.
    So LabVIEW will not run the VI, I posted a screenshot with the new Array in the BD. As you can see, the wire now has two lines instead of one.
    You can always add suitable FP indicators by right-clicking -> create -> indicator.
    Please let me know if this is useful for you.
    I am looking forward to hearing from you!
    Have a nice day,
    Christopher W.
    Intern Application Engineering | NI Certified LabVIEW Associate Developer (CLAD) | NI Germany
    Attachments:
    array-wire.png ‏24 KB

  • How to convert Pack-decimal values?

    I have one itab1 with field
    Rate DEC 20,5
    Another Itab2 with field
    Rate DEC 18,9
    i am doing...
    itab2-rate = itab1-rate
    but it is not let me doing  my value to second table . how?
    How it can be done?
    RH

    Hi Ronny,
    <removed_by_moderator>
    Edited by: Julius Bussche on Sep 9, 2008 5:37 PM

Maybe you are looking for