Converting Dates between TimeZone

I need to convert the date&time into German date&time. Problem is Calender's time zone setting seems not to work as expected or I'm implementing it incorrectly. Here is the scenario:
I/P Date String: 20100101101515 (yyyyMMddhhmmss format)
Base on condition, I need to apply offset:
I/P GMT time: During winter months apply +1 hour offset, during summer months apply +2 hour offset.
I/P London time: Apply +1 hour offset
My understanding was that the setting time zone in calender would automatically take care of winter/summer timings. But this doesn't seem to work. If anyone could provide a sample code.

This doesn't seem to work. Here is what I have written:
public class TimeZoneTest {
     public static void main(String[] args) throws Exception {
          String source = "20100223101500";
          DateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
          dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
          Date date = dateFormat.parse(source);
          System.out.println("Date 1 : " + date);
          DateFormat dateFormat2 = new SimpleDateFormat("yyyyMMddhhmmss");
          dateFormat2.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
          Date date2 = dateFormat2.parse(dateFormat2.format(date));
          System.out.println("Date 2 : " + date2);
}O/P is
Date 1 : Tue Feb 23 10:15:00 GMT 2010
Date 2 : Tue Feb 23 10:15:00 GMT 2010

Similar Messages

  • Converting dates and timezones

    I have a third-party application that is feeding me data. I will get a particular line and it will include a message time in GMT and the local timezone offset as a number (-5, -6, etc.) rather than as a Timezone. I need to get the actual local time of the message so I can process the row. I looked at the NEW_TIME() built-in function, but it doesn't look like it can handle the offset by itself - it wants the original and new timezone in text. The tricky part is that this is a vehicle tracking application, so vehicles will be in various timezones. Add in the complications of dealing with daylight savings and this quickly becomes a chore.
    Has anyone got a quick little function (an ADD_HOURS function similar to an ADD_MONTHS would be perfect) that can convert the date I am given (accounting for changes in Daylight Savings)? The best would be a simple function that just takes a date value and an offset in hours and returns the new/converted date. Thanks in advance.

    Thanks for the link. After doing some digging and experimenting, I was able to use the following to get what I need:
    DECLARE
      tmp_dttm      DATE;
      tmp_tz        VARCHAR2(3);
      v_dttm        DATE;
    BEGIN
      tmp_dttm   :=  :NEW.LOCATION_DATE;
      tmp_tz     :=  :NEW.LOCATION_TIMEZONE;
      --Convert the time to local
      v_sql  := 'select to_date('''|| to_char(tmp_dttm,'MM/DD/YYYY HH24:MI:SS')||''',''MM/DD/YYYY HH24:MI:SS'')'||'+INTERVAL '''|| tmp_tz ||''' HOUR from dual';
      dbms_output.put_line ('SQL String: ' || v_sql);
      execute immediate v_sql into v_dttm ;
    ...The INTERVAL function is what I was looking for.

  • How to convert date in varchar format to TimeZone format?

    Hi,
    Iam having a date '14-05-08 09:46:35 AM' (in Varchar format). How to convert this date to TimeZone ('IYYY-MM-DD"T"HH12:MI:SS"Z"FX') format?
    For Example,
    My input date is '14-05-08 09:46:35 AM' and I need output as '2008-05-14T09:46:35Z'.
    How to convert this?
    Thanks in Advance.

    Hi,
    You would look up the TO_TIMESTAMP and the TO_CHAR functions in the SQL reference manual for the version you don't mention, and make up the solution yourself, rather than asking someone else to do your homework.
    Sybrand Bakker
    Senior Oracle DBA

  • Oracle Database : Date conversion issue between timezones

    Hi All,
    We are trying to convert date from Eurpoer/Amsterdam timezone to Australia/Sydnet timezone and extracting time out of it.
    We are facing issue related to incorrect timing after conversion.
    Please find below issue details,
    Environment
    Database: Oracle 10.2.0.4
    Machine: Linux RHEL 4
    Location: Amsterdam, Netherlands
    Issue: After converting date from Eurpoer/Amsterdam timezone to Australia/Sydnet timezone
    SELECT TO_CHAR (FROM_TZ (TO_TIMESTAMP ('201110201416', 'YYYYMMDDHH24MI'),
    DBTIMEZONE
    ) AT TIME ZONE 'Australia/Sydney', 'HH24:MI')
    FROM DUAL
    Output of above SQL is 22:16.
    Expected output is 23:16
    Database Timezone (DBTIMEZONE) is set to +02:00 (i.e. GMT + 2) (Europe/Amsterdam)
    If we convert date to Australia/Tasmania timezone then we get expected output i.e. 23:16.
    Question: Expected time for Australia/sydney is 23:16, but why Oracle database provides 22:16 as output.
    Please note that, Sydney and Tasmania comes under same timezone. Still we get different output for both the timezone.
    Oracle database considers GMT + 10 for Australia/sydney and GMT + 11 for Australia/Tasmania.
    If we want to use Australia/sydney then how should we get correct sydney time?
    Regards
    Shailendra

    I made a test and it showed when I omit TO_CHAR, both queries have the same result 11:15 PM. So it's TO_CHAR which is the 'culprit'. Since this is a globalization issue, you may repeat your question in this forum:
    Globalization Support
    (So one of the moderators moves the thread to this forum).
    Werner
    By the way my local timezone is Europe/Berlin, there should be no difference to Amsterdam.

  • Converting time between time zones

    I would like to convert a user input date between 2 time zones, for example between America/Chicago and Europe/Paris. So, when user enters 2005-02-10 13:00 America/Chicago, I need to calculate this time in Paris accounting for any daylight savings time. Could someone point me in the right direction to accomplish this. I believe, java.text.SimpleDateFormat can be used, but I can't get this to work. Thanks

    I would like to convert a user input date between 2
    time zones, for example between America/Chicago and
    Europe/Paris. So, when user enters 2005-02-10 13:00
    America/Chicago, I need to calculate this time in
    Paris accounting for any daylight savings time.
    Could someone point me in the right direction to
    o accomplish this. I believe,
    java.text.SimpleDateFormat can be used, but I can't
    get this to work. Thanks
         try
              String tz=TimeZone.getTimeZone("America/Chicago").getDisplayName();
              java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm z");
              Date d=sdf.parse("2005-02-10 13:00 "+tz);
              sdf.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
              System.out.println("Time in Paris: "+sdf.format(d));
         catch(Exception e){e.printStackTrace();}I dont know whether it is really working. Splitting of date -time and timezone has to be considered

  • Error "Conversion failed when converting date and/or time from character string" to execute one query in sql 2008 r2, run ok in 2005.

    I have  a table-valued function that run in sql 2005 and when try to execute in sql 2008 r2, return the next "Conversion failed when converting date and/or time from character string".
    USE [Runtime]
    GO
    /****** Object:  UserDefinedFunction [dbo].[f_Pinto_Graf_P_Opt]    Script Date: 06/11/2013 08:47:47 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE   FUNCTION [dbo].[f_Pinto_Graf_P_Opt] (@fechaInicio datetime, @fechaFin datetime)  
    -- Declaramos la tabla "@Produc_Opt" que será devuelta por la funcion
    RETURNS @Produc_Opt table ( Hora datetime,NSACOS int, NSACOS_opt int)
    AS  
    BEGIN 
    -- Crea el Cursor
    DECLARE cursorHora CURSOR
    READ_ONLY
    FOR SELECT DateTime, Value FROM f_PP_Graficas ('Pinto_CON_SACOS',@fechaInicio, @fechaFin,'Pinto_PRODUCTO')
    -- Declaracion de variables locales
    DECLARE @produc_opt_hora int
    DECLARE @produc_opt_parc int
    DECLARE @nsacos int
    DECLARE @time_parc datetime
    -- Inicializamos VARIABLES
    SET @produc_opt_hora = (SELECT * FROM f_Valor (@fechaFin,'Pinto_PRODUC_OPT'))
    -- Abre y se crea el conjunto del cursor
    OPEN cursorHora
    -- Comenzamos los calculos 
    FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
    /************  BUCLE WHILE QUE SE VA A MOVER A TRAVES DEL CURSOR  ************/
    WHILE (@@fetch_status <> -1)
    BEGIN
    IF (@@fetch_status = -2)
    BEGIN
    -- Terminamos la ejecucion 
    BREAK
    END
    -- REALIZAMOS CÁLCULOS
    SET @produc_opt_parc = (SELECT dbo.f_P_Opt_Parc (@fechaInicio,@time_parc,@produc_opt_hora))
    -- INSERTAMOS VALORES EN LA TABLA
    INSERT @Produc_Opt VALUES (@time_parc,@nsacos, @produc_opt_parc)
    -- Avanzamos el cursor
    FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
    END
    /************  FIN DEL BUCLE QUE SE MUEVE A TRAVES DEL CURSOR  ***************/
    -- Cerramos el cursor
    CLOSE cursorHora
    -- Liberamos  los cursores
    DEALLOCATE cursorHora
    RETURN 
    END

    You can search the forums for that error message and find previous discussions - they all boil down to the same problem.  Somewhere in your query that calls this function, the code invoked implicitly converts from string to date/datetime.  In general,
    this works in any version of sql server if the runtime settings are correct for the format of the string data.  The fact that it works in one server and not in another server suggests that the query executes with different settings - and I'll assume for
    the moment that the format of the data involved in this conversion is consistent within the database/resultset and consistent between the 2 servers. 
    I suggest you read Tibor's guide to the datetime datatype (via the link to his site below) first - then go find the actual code that performs this conversion.  It may not be in the function you posted, since that function also executes other functions. 
    You also did not post the query that calls this function, so this function may not, in fact, be the source of the problem at all. 
    Tibor's site

  • How we can view convert data after XSLT mapping & before Graphical mapp

    Hello Friends,
    Currently i am working on XI standard content. In this client need some customization.
    In interface mapping, XSLT mapping on 1st position & Graphical mapping on 2nd position.
    As per my understanding 1st XSLT mapping will be exected then Graphical mapping.
    Can I see or check convert data from XSLT mapping.
    I want to check data between XSLT mapping & Graphical mapping.
    Kindly help me out.
    Regards,
    Narendra

    >
    Narendra GSTIT wrote:
    > I dont want to test standalone XSL Code.
    >
    > The data which I get from Source interface and after XSLT mapping I want to check this that my XSLT code is going well or not.
    >
    > i.e. check for proper input & get proper output.
    You have ro do standalone testing of the XSLT mapping.....Interface Mapping or Interface Determination will give you output message which will be that of message mapping (the last mapping)
    What is the issue in testing the XSLT mapping alone?...may be in Stylus Studio.
    Just ensure that XSLT mapping produces proper output and then this output message of XSLT is the input to your Message Mapping.....once the entire Interface mapping gets executed then it would mean that all the included mapping programs work fine.
    Regards,
    Abhishek.

  • Find to find date between 05/01/2003 and 05/29/2003

    Indeed, it's something about sql...
    I write a programme to have query on access database
    I try to
    sql="select * from PO where Date between to_date('05012003','mmddyyyy') and to_date('05292003','mmddyyyy')";
    but it's doesn't work...why?no (to_date) function in access??
    pls help!!

    When you are going through java to any database it uses a third party bridge that converts the SQL statements into something that the target database understands. Some of these third party bridges only conform to true SQL statements. Best to find out how the bridge functions.
    As such Java supports the ANSI SQL-2 standard.
    I imagine others will correct any errors in my statement, but I belive my answer is esentially right. Of course the jist of it is that you are going to have to find out how the particular bridge you are using handles date manipulations, It has little to nothing to do with the underlying database and everything to do with the connection bridge software.

  • Compare Date with Timezone

    Hi,
    I have a Date which is stored in the Database with the timezone like GMT, I have a java.util.Date which is selected in my UI from a Customized Calendar, I am converting this Date with timezone and want to compare this date with the date with timezone stored in the DB? How to accomplish this, please shed some light into this?
    Thanks.

    797836 wrote:
    I have a Date which is stored in the Database with the timezone like GMT, I have a java.util.Date which is selected in my UI from a Customized Calendar, I am converting this Date with timezone and want to compare this date with the date with timezone stored in the DB?As Parul said, Date does not involve a timezone. I think you need to clarify what you mean by "I am converting this Date with timezone", because it doesn't make much sense to me.
    BTW: If the date in your database is a standard SQL Date, then it will be converted to a java.sql.Date when you read it into Java with JDBC. And java.sql.Date is directly comparable with java.util.Date (in fact, it's a subclass).
    Winston

  • Converting Date of Bith to Age

    Is it possible to use a formula to convert a whole column of DOB's into ages.
    Thanks

    TSCM88 wrote:
    Thank you very much Barry, your post was very helpful. I took your advice and downloaded the user guides. My aim is to convert dates into years and months. I have tried to create a formula for this but it will not work, would very much appreciate any tips. I am unable to combine the DATEIF function with a month calculating function, i have been trying EDATE.
    Depends what you mean by "a month calculating function" and "combine".
    Did you check the DATEDIF entry in the F&F User Guide and try some of the calculation methods listed?
    You can calculate the difference between two dates in years, months, weeks or days, or combinations of these.
    This formula, for instance will give the age today in years and months for a birthdate placed in column B:
    =DATEDIF(B,TODAY(),"Y")&"y, "&DATEDIF(B,TODAY(),"YM")&"m"
    Regards,
    Barry

  • Calendar, date and timezone

    Hi everybody,
    I'm using the CLLocation class and I cannot find any documentation on it in google. DO you know where it is ?
    I know how to get the timestamp for the date, but here are some questions about it :
    -Does this date include the timezone value so I know from my position what is the timezone ?
    -How to convert the timestamp (NSDate instance I think) into a NSCalendar with which I could get the timezone information ?
    Thank you

    Because the Timezone isn't part of the timestamp for a date.
    This is one thing that Java got right. Think of it this way. There is no such thing as just 9.am. It's 9am in a specific place (timezone) on the Earth. Because at the same time it's 9am in one timezone it's 1pm in another timezone and 11:30 am in another timezone. etc. But all these representations of the time actually hold the exact same long millisecond value.
    So you never hold the timezone as part of the date. Timezones are only used for display or for parsing a value in.

  • CONVERT   DATE RANGE INTO MONTHS

    HI FRIENDS,
    ACTUALLY IN MY SELECT-OPTIONS I HAVE USED DATE BETWEEN 03/06/1980  TO 04/12/1980
    BASED ON THIS DATE I HAVE TO CALCULATE NUMBER OF MONTHS.
    WILL THIS BE DONE AUTOMATICALLY OR I NEED TO WRITE ANY CODE FOR CONVERTING THE DATE RANGE INTO NUMBER OF MONTHS.
    REGARDS
    SIRI.

    Hi,
    Use FM's : MONTHS_BETWEEN_TWO_DATES_NEW
               MONTHS_BETWEEN_TWO_DATES
               FIMA_DAYS_AND_MONTHS_AND_YEARS
    Sample code :
    DATA : x_no_months type i.
    DATA : x_stdat like sy-datum,
           x_enddat like sy-datum.
           x_stdat  = s_date-low
           x_enddat = s_date-high
    CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
        EXPORTING
          i_datum_bis = x_stdat
          i_datum_von = x_enddat
        IMPORTING
          e_monate    = x_no_months.
    x_no_months will contain no.of months.
    Regards
    Appana

  • Need to convert  Date from calendar to String in the format dd-mom-yyyy

    Need to convert Date from calendar to String in the format dd-mom-yyyy+..
    This is absolutely necessary... any help plz..
    Rgds
    Arwinder

    Look up the SimpleDateFormat class: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
    Arwinder wrote:
    This is absolutely necessary... any help plz..For you maybe, not others. Please refrain from trying to urge others to answer your queries. They'll do it at their own pace ( if at all ).
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • What is the best way to load and convert data from a flat file?

    Hi,
    I want to load data from a flat file, convert dates, numbers and some fields with custom logic (e.g. 0,1 into N,Y) to the correct format.
    The rows where all to_number, to_date and custom conversions succeed should go into table STG_OK. If some conversion fails (due to an illegal format in the flat file), those rows (where the conversion raises some exception) should go into table STG_ERR.
    What is the best and easiest way to archive this?
    Thanks,
    Carsten.

    Hi,
    thanks for your answers so far!
    I gave them a thought and came up with two different alternatives:
    Alternative 1
    I load the data from the flat file into a staging table using sqlldr. I convert the data to the target format using sqlldr expressions.
    The columns of the staging table have the target format (date, number).
    The rows that cannot be loaded go into a bad file. I manually load the data from the bad file (without any conversion) into the error table.
    Alternative 2
    The columns of the staging table are all of type varchar2 regardless of the target format.
    I define data rules for all columns that require a later conversion.
    I load the data from the flat file into the staging table using external table or sqlldr without any data conversion.
    The rows that cannot be loaded go automatically into the error table.
    When I read the data from the staging table, I can safely convert it since it is already checked by the rules.
    What I dislike in alternative 1 is that I manually have to create a second file and a second mapping (ok, I can automate this using OMB*Plus).
    Further, I would prefer using expressions in the mapping for converting the data.
    What I dislike in alternative 2 is that I have to create a data rule and a conversion expression and then keep the data rule and the conversion expression in sync (in case of changes of the file format).
    I also would prefer to have the data in the staging table in the target format. Well, I might load it into a second staging table with columns having the target format. But that's another mapping and a lot of i/o.
    As far as I know I need the data quality option for using data rules, is that true?
    Is there another alternative without any of these drawbacks?
    Otherwise I think I will go for alternative 1.
    Thanks,
    Carsten.

  • Error converting data type nvarchar to numeric 'witholding tax' (OWHT)

    Hi Guys.
    After I have upgraded my clients 2007 PL 30 database to 8.81 PL05, and running a repair to fix inconsistincies, I am receiveing some error when opening any sales documents.
    It takes place when I open a sales document, or browse previous docs. When browsing previous docs, it onlly happens on some of them.
    I also receive a different error when viewing sales orders: Error converting data type nvarchar to numeric (CRD2).
    Any ideas how to fix it?
    It does not limit me from processing and using the rest of the functionality. All calculations with queries in the docs are still working.
    Thanks.

    Hi,
    Please check Note No. : 1402855 and see if the same applied to the issue mentioned by you.
    Kind Regards,
    Jitin
    SAP Business One Forum Team

Maybe you are looking for

  • RIM Error Message?? Need Help!

    I have been getting dozens per hour...the following is a sample...anyone know what this is and how I can get it to stop??? RIM_bca28a80-e9c0-11d1-87fe-00600811c6a2 This message is used to carry data between the BlackBerry handheld and an associated s

  • Where does Javascript run within a JSP in Commerce Server

              I am currently using BEA Commerce Server and written some JSPs to be used in the           application. I am trying to carry out some validation of some fields in my JSP           and thats how javascript came up.           The question I h

  • Pink Floyd documentary from iTunes only plays audio on iPad?

    I downloaded the new remastered version of Pink Floyd's "The Wall" and it included a documentary called "Behind the Wall." The video plays fine on my iMac and on my iPhone, but on my iPad 2, it only plays the audio. I tried hitting "command-i" so i c

  • XSLT pmd.xml - html

    I needed to have this, but couldn't find anything that allowed me to do it quickly. I'm not using Maven. After scouring the web for a general solution for PMD I came across an xslt file, which I modified to better represent FlexPMD (there are subtle

  • I want to publish my book for my personal use. Can I?

    If I publish my iBook I created with iBooks Author, can I just have it for my personal use? I don't to sell my book,