Yet another string to date format  question

I have searched the forums and cannot find the exact answer I am looking for so here goes.
SimpleDateFormat sdf = new SimpleDateFormat("M/d/y");
String strDate = "02/25/04";
Date myDate = sdf.parse(strDate);
gives me : Wed Feb 25 00:00:00 EST 2004
but I need the output of myDate to stay 02/25/04 in order to add the date object to a sql query.
strDate will come from request.getParameter variable.
Any help would be greatly appreciated.

>
This will only work if I return the value as a string,
which puts me back right where I started. I simply
cannot get the formatted value Wed Feb 25 00:00:00 EST
2004 to return as a Date object 02/25/04. Is this
possible? When using SQL, as stated above use a PreparedStatement.
Use the setDate/setTimestamp/setTime methods to put it into the database.
Use getDate/getTimestamp/getTime to get it out.
The 'Date' classes do NOT store anything as "02/25/04". They store milliseconds since the epoch in UMT (Universal Mean Time = Greenwich Mean Time.) That is all they store.
When you display a 'Date' instance it is converted to a display format. You can use SimpleDateFormat to create any display format that you want.

Similar Messages

  • I want convert string to date format in Oracle

    Dear All
    I want convert string to date format in Oracle,Format is given below
    'Friday, 02 March 2012 2:44 PM' to '02/03/2012 2:44 PM'

    >
    Hi Parwez,
    I want convert string to date format in Oracle,Format is given below
    'Friday, 02 March 2012 2:44 PM' to '02/03/2012 2:44 PM'SELECT TO_DATE('Friday, 02 March 2012 2:44 P.M.', 'DAY, DD MONTH YYYY HH:MI A.M.') from dual;
    As well as what the other poster suggested, look here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34924
    HTH,
    Paul...

  • How to convert a String to Date format?

    the user enter a date in string format and the date is save in the database.
    The problem i am facing is i want to change from String to Date format.
    Here is my codes:
            public boolean insertData() throws Exception {
            boolean validFlag = false;
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date d = df.parse("05/18/05");
            String MY_DATE_FORMAT = "yyyy-MM-dd";
            String jobAdvertisementDate = new SimpleDateFormat(MY_DATE_FORMAT).format(d);
            String sql = "INSERT INTO companyjob (CompanyID,JobID, JobAdvertisementDate ) " +
                    " VALUES ('" + companyID + "','" + jobID + "', '" + jobAdvertisementDate + "')";
            System.out.println(sql);
            validFlag = executeSQL(sql);
            return validFlag;
        }The date is save under jobAdvertisementDate.
    My netbeans shows an error. There's a red line under DateFormat and parse inside my codes.
    PLease help me. Reply asap!!

    BebeGirl wrote:
    My netbeans shows an error. There's a red line under DateFormat and parse inside my codes.
    Red Line? Sounds ominous. I wonder what it means.
    So...what does the error say?

  • String to DATS format conversion in XI.

    Hello Experts,
    I am using Powerbuilder system to get my Legacy data.In Powerbuilder Date needs to be supplied in STRING format.So I am giving String Format (dd-mmm-yyyy).
    However, at SAP end, Date needs to be in DATS format (Standard SAP yyyymmdd) .
    In Message Mapping I have given I/P structure as String and O/P structure as DATS format. When I test mapping in XI, it gives me Parseable error.
    Can anybody tell me, is there any way in XI to convert from String to DATS format so that I do not get Parseable error.
    Please Help!!!!

    Lokesh,
    With XI there is a date transformation function under date category there you need to provide source date format and target date format..
    I have used the same for fetching the data from oracle..and posting into SAP..it works fine..
    Try this ..this will solve ur problem....you just need to see what is the exact date format used by powerbuilder internally...
    Regards,

  • String to DATS format Conversion

    Hello Experts,
    I am using Powerbuilder system to get my Legacy data.In Powerbuilder Date needs to be supplied in STRING format.So I am giving String Format (dd-mmm-yyyy).
    However, at SAP end, Date needs to be in DATS format (Standard SAP yyyymmdd) .
    In Message Mapping I have given I/P structure as String and O/P structure as DATS format. When I test mapping in XI, it gives me Parseable error.
    Can anybody tell me, is there any way in XI to convert from String to DATS format so that I do not get Parseable error.
    Please Help!!!!

    Lokesh,
    With XI there is a date transformation function under date category there you need to provide source date format and target date format..
    I have used the same for fetching the data from oracle..and posting into SAP..it works fine..
    Try this ..this will solve ur problem....you just need to see what is the exact date format used by powerbuilder internally...
    Regards,

  • Converting a string into Date format

    I am currently using a JSP.
    I currently need to convert a string that holds a date in "dd/mm/yyyy" format to the jva.sql.Date format.
    Any ideas as to what the proper way of doing this is?
    Many thanks ppl

    public java.sql.Date parseDate(String s) {
         java.text.DateFormat dateFormatter= new java.text.SimpleDateFormat("dd/MM/yyyy");
         return new java.sql.Date(dateFormatter.parse(s).getTime());

  • SQL Date Format question

    Hello,
    The date format in an Access database is "Date Time" (
    1/8/2008 6:14:34
    AM ). It's a required format for some functions.
    I need to group product orders by date for a simple revenue
    summary page.
    As the time part of the date is different for all orders,
    trying to group
    all orders by one date ( 1/8/2008 for example ) won't work.
    It results in:
    1/8/2008 6:14:34 AM $30.00
    1/8/2008 7:50:23 AM $20.00
    I need it to be:
    1/8/2008 $50.00
    I've tried convert and datetime but am having some kind of
    brain cramp I
    think and can't get it to work.
    The base SQL is:
    SELECT order_Date, Sum(order_Total) as TotalAmt FROM
    OrderDetails
    GROUP BY order_Date
    Usage:
    <% While ((Repeat1__numRows <> 0) AND (NOT
    Recordset1.EOF)) %>
    <td><%= Recordset1("order_Date") %></td>
    <td><%= Recordset1("TotalAmt") %></td>
    Repeat1__index=Repeat1__index+1
    Repeat1__numRows=Repeat1__numRows-1
    Recordset1.MoveNext()
    Wend
    %>
    Any ideas are appreciated.
    Take care,
    Tim
    Take care,
    Tim
    www.bestbabystuffonline.com

    Hi Baxter,
    I will be summing the totals, but I haven't added that yet.
    The date format was the big hurdle.
    I just have to figure out how to format the date back to
    mm/dd/yyy in the
    repeat region on the page now.
    It's coming out of the rs as yyyy/mm/dd
    <%=Recordset1("orderDate")%>
    I'm thinking I'll need to set up a function to format the way
    orderDate
    displays.
    <%=FriendlyDate(Recordset1("orderDate"))%>
    But, time for a break. Thanks again for the ideas.
    Take care,
    Tim
    "Baxter" <baxter(RemoveThe :-)@gtlakes.com> wrote in
    message
    news:[email protected]...
    >I also thought that you were Summing the totals from the
    order that the
    >item
    > was placed at a different time or is the sum the total
    from just one time
    > stamp?
    > SELECT order_Date, Sum(order_Total) as TotalAmt FROM
    OrderDetails
    > GROUP BY order_Date
    >
    > "TC2112" <[email protected]> wrote in message
    > news:[email protected]...
    >> I got it to group and order correctly with this:
    >>
    >> "SELECT FORMAT(order_Date, 'yyyy/mm/dd') AS
    OrderDate FROM
    > cwq_OrderDetails2
    >> GROUP BY FORMAT(order_Date, 'yyyy/mm/dd') ORDER BY
    FORMAT(order_Date,
    >> 'yyyy/mm/dd') DESC"
    >>
    >> All three had to have the same format (there was the
    brain cramp).
    >>
    >> It takes this data:
    >>
    >> 1/8/2008 6:14:34 AM
    >> 1/8/2008 7:50:23 AM
    >> 1/10/2008 8:50 AM
    >> 1/9/2008 9:01 AM
    >>
    >> and shows it in the recordset as:
    >>
    >> 2008/01/10
    >> 2008/01/09
    >> 2008/01/08
    >>
    >>
    >> Which is perfect. It's gouped and ordered
    descending..
    >>
    >> Now all I need to do is change the display format on
    the page to
    > mm/dd/yyyy
    >> here:
    >>
    >>
    >> <%=Recordset1("orderDate")%>
    >>
    >> Thanks again,
    >>
    >> Tim
    >>
    >>
    >> "Baxter" <baxter(RemoveThe :-)@gtlakes.com>
    wrote in message
    >> news:[email protected]...
    >> > Do you have a order_number field in the
    database you could
    >> > GROUP BY order_number
    >> > Dave
    >> > "TC2112" <[email protected]> wrote in
    message
    >> > news:[email protected]...
    >> >> Hi Baxter,
    >> >>
    >> >> That allows for the correct format to be
    displayed, but it's the
    >> >> format
    >> >> in
    >> >> the recordset that needs to be set at just
    the date so it can be
    > grouped.
    >> >>
    >> >> I'm pretty close with this:
    >> >>
    >> >> "SELECT FORMAT(order_Date, 'mm/dd/yyyy') AS
    OrderDate FROM
    >> >> tblOrderDetails
    >> >> ORDER BY FORMAT(order_Date, 'yyyy/mm/dd')
    DESC"
    >> >>
    >> >> It returns
    >> >>
    >> >> 1/10/2008
    >> >> 1/9/2008
    >> >> 1/8/2008
    >> >> 1/8/2008
    >> >> 1/8/2008
    >> >>
    >> >>
    >> >> Now I just need to figure out the GROUP BY
    in the SQL to return this:
    >> >>
    >> >> 1/10/2008
    >> >> 1/9/2008
    >> >> 1/8/2008
    >> >>
    >> >> GROUP BY order_Date doesn't work as
    order_date in the DB contains the
    >> >> minutes.
    >> >> GROUP BY FORMAT(order_Date, 'mm/dd/yyyy')
    throws an error.
    >> >>
    >> >> Thanks for the ideas :-)
    >> >>
    >> >> Tim
    >> >>
    >> >>
    >> >>
    >> >>
    >> >> "Baxter" <baxter(RemoveThe
    :-)@gtlakes.com> wrote in message
    >> >> news:[email protected]...
    >> >> > Try this, open the Bindings panel and
    select the date field in the
    >> >> > recordset
    >> >> > then to the right
    >> >> > of the panel you will see a column
    header called format on the right
    >> > side
    >> >> > of
    >> >> > the panel ( if you cant see it expand
    the panel box) click the
    > dropdown
    >> >> > arrow and pick the date format you
    want to display on the page from
    > the
    >> >> > Date/Time selections.. Hope this helps
    you.
    >> >> > Dave
    >> >> >
    >> >> > "TC2112" <[email protected]>
    wrote in message
    >> >> >
    news:[email protected]...
    >> >> >> Hi Baxter,
    >> >> >>
    >> >> >> I need to keep the current Date
    Time format in the database table
    >> >> >> as
    >> > some
    >> >> >> other functions need the long
    format.
    >> >> >>
    >> >> >> I'm just trying to format to short
    date in the recordset so I can
    >> >> >> group
    >> >> >> by
    >> >> >> it and have any orders, regardless
    of time, group in a single date.
    >> >> >>
    >> >> >> Thanks,
    >> >> >> Tim
    >> >> >>
    >> >> >> "Baxter" <baxter(RemoveThe
    :-)@gtlakes.com> wrote in message
    >> >> >>
    news:[email protected]...
    >> >> >> > In your order_Date field in
    the database design view set the
    > format
    >> > to
    >> >> >> > Short
    >> >> >> > Date Default Value Now()
    >> >> >> > That should work for you.
    >> >> >> > Dave
    >> >> >> > "TC2112"
    <[email protected]> wrote in message
    >> >> >> >
    news:[email protected]...
    >> >> >> >> Hello,
    >> >> >> >>
    >> >> >> >> The date format in an
    Access database is "Date Time" ( 1/8/2008
    >> >> >> >> 6:14:34
    >> >> >> >> AM ). It's a required
    format for some functions.
    >> >> >> >>
    >> >> >> >> I need to group product
    orders by date for a simple revenue
    > summary
    >> >> > page.
    >> >> >> >> As the time part of the
    date is different for all orders, trying
    > to
    >> >> > group
    >> >> >> >> all orders by one date (
    1/8/2008 for example ) won't work.
    >> >> >> >> It results in:
    >> >> >> >>
    >> >> >> >> 1/8/2008 6:14:34 AM
    $30.00
    >> >> >> >> 1/8/2008 7:50:23 AM
    $20.00
    >> >> >> >>
    >> >> >> >> I need it to be:
    >> >> >> >>
    >> >> >> >> 1/8/2008 $50.00
    >> >> >> >>
    >> >> >> >> I've tried convert and
    datetime but am having some kind of brain
    >> > cramp
    >> >> > I
    >> >> >> >> think and can't get it to
    work.
    >> >> >> >>
    >> >> >> >> The base SQL is:
    >> >> >> >>
    >> >> >> >> SELECT order_Date,
    Sum(order_Total) as TotalAmt FROM
    >> >> >> >> OrderDetails
    >> >> >> >> GROUP BY order_Date
    >> >> >> >>
    >> >> >> >> Usage:
    >> >> >> >>
    >> >> >> >> <% While
    ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) %>
    >> >> >> >>
    >> >> >> >> <td><%=
    Recordset1("order_Date") %></td>
    >> >> >> >> <td><%=
    Recordset1("TotalAmt") %></td>
    >> >> >> >>
    >> >> >> >>
    Repeat1__index=Repeat1__index+1
    >> >> >> >>
    Repeat1__numRows=Repeat1__numRows-1
    >> >> >> >> Recordset1.MoveNext()
    >> >> >> >> Wend
    >> >> >> >> %>
    >> >> >> >>
    >> >> >> >>
    >> >> >> >>
    >> >> >> >> Any ideas are
    appreciated.
    >> >> >> >>
    >> >> >> >> Take care,
    >> >> >> >> Tim
    >> >> >> >>
    >> >> >> >>
    >> >> >> >> --
    >> >> >> >> Take care,
    >> >> >> >>
    >> >> >> >> Tim
    >> >> >> >>
    >> >> >> >>
    www.bestbabystuffonline.com
    >> >> >> >>
    >> >> >> >>
    >> >> >> >
    >> >> >> >
    >> >> >>
    >> >> >>
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >
    >>
    >>
    >
    >

  • How to convert string to date format?

    Hi All,
    String is in following format: 2006-12-07 i.e yyyy-mm-dd
    I want it in 07.12.2006 date format.
    which function module should i used to convert it?
    Regards,
    Nilima

    an other way to do this :
    Code
    DATA :
    ld_text(20) TYPE c,
    ld_date TYPE datum.
    ld_text = '2006-12-07'.
    REPLACE ALL OCCURENCES OF '-' IN ld_text WITH ''.
    WRITE ld_text TO ld_date.
    WRITE ld_date.

  • String into date format

    Hi
    I was wondering if anyone knew how to convert a string into different formats,
    to enable it to be stored in a mysql db.
    I was wondering anyone you knew how to convert:
    - String into the date format yyyy-mm--dd
    - String into time format 00:00:00
    - string to double
    Ive tried:
    c_date = java.sql.Date.valueOf(f_date);
    System.out.println("conversion data: " +c_date);
    c_time = java.sql.Time.valueOf(f_time);
    System.out.println(" time converted data: "+c_time);
    // string to double conversion
    c_change = java.lang.Double.valueOf(f_change);
    System.out.println(c_change);
    My class doesnt execute this at all?
    Also,
    SimpleDateFormat sdft = new SimpleDateFormat("yyyy-MM-dd");
    c_date = sdft.format(f_date);
    System.out.println(c_date);
    .. but this method returns the error incompatible types?
    Any suggestions would be helpful.. thanks in advance..

    Friends i've got similar kind of problem...can you help me
    here is my code. When i try to print the user entered date (dd/MM/yyyy)(which i am storing in a string) the program dispalys nothing. and everey time i enter a valid date it displas "invalid From date entered ". I need to store the user entered date into a string because i need that for further use. All my intesion is to get two dates from user in dd/MM/yyyy. Strore them in certain variable. Check if they are valid or not. and make sure todate is either equal or greater than fromdate. Please help me to solve this problem.
    public class EDTDateValidation extends JFrame implements ActionListener{
    private JLabel fromlabel;
    private JLabel tolabel;
    private JTextField fromtxt;
    private JTextField totxt;
    private String fmt ="dd/MM/yyyy";
    private java.lang.String fromdate;
    private java.lang.String todate;
    private JButton buttonOK;
    private JButton buttonCancel;
    private Date theDate;
    private Date date1;
    private Date date2;
    private JPanel mainPanel;
    SimpleDateFormat dtformat = new SimpleDateFormat(fmt);
    public EDTDateValidation(){
    super("Date Validation");
    dtformat.setLenient(false);
    mainPanel=new JPanel();
    mainPanel.setLayout(null);
    fromlabel = new JLabel("From Date");
    tolabel = new JLabel("To Date");
    buttonOK = new JButton("OK");
    buttonCancel = new JButton("Cancel");
    fromdate = new String();
    todate = new String();
    fromtxt = new JTextField(10);
    totxt = new JTextField(10);
    fromdate = fromtxt.getText();
    todate = totxt.getText();
    mainPanel.add(fromlabel);
    fromlabel.setBounds(20,20,50,15);
    mainPanel.add(tolabel);
    tolabel.setBounds(20,50,50,15);
    mainPanel.add(fromtxt);
    fromtxt.setBounds(90,20,130,20);
    mainPanel.add(totxt);
    totxt. setBounds(90,50,130,20);
    mainPanel.add(buttonOK);
    buttonOK.setBounds(70,80,71,23);
    mainPanel.add(buttonCancel);
    buttonCancel.setBounds(150,80,71,23);
    buttonOK.addActionListener(this);
    buttonCancel.addActionListener(this);
    setContentPane(mainPanel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(247,140);
    setResizable(false);
    //pack();
    public static void main(String args[]) {
    try {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    catch(Exception e) {
    System.err.println("Could not load Look and Feel" + e);
    EDTDateValidation edtDateVal = new EDTDateValidation();
    edtDateVal.setVisible(true);
    public void actionPerformed(ActionEvent e) {
    if(e.getSource() == buttonOK){
    System.out.println(fromtxt.getText());
    System.out.println(fromdate); //THIS PRINTS BLANK
    System.out.println(todate); //THIS ASWELL
    try {
    Date date = null;
    date = dtformat.parse(fromdate);
    System.out.println("valid From date entered!");
    catch(Exception f) {
    System.out.println("Invalid From date entered!");
    // textField1.setText("");
    return;
    try {
    Date date = null;
    date = dtformat.parse(todate);
    System.out.println("valid TO date entered!");
    catch(Exception f) {
    System.out.println("Invalid To date entered!");
    // textField1.setText("");
    return;
    }

  • Test String for date format

    Is there a function that reads a string and can return yes/no if the string matches a specified date format (example: mm/dd/yy)? I wish to avoid parsing the string character by character.
    Thanks,
    George

    BTW,
    I used the following example code available from this site. I was able to easily modify it to sovle my problem.
    try {
    SimpleDateFormat formatter =
    new SimpleDateFormat("EEEE, MMMM dd, yyyy");
    Date d = formatter.parse(
    "Tuesday, January 03, 1956");
    formatter = new SimpleDateFormat(
    "EE, MMM d, yy");
    d = formatter.parse("Tue, Jan 3, 56");
    formatter = new SimpleDateFormat(
    "EE, MM d, yy");
    d = formatter.parse("Tue, 01 3, 56");
    process(d);
    } catch (ParseException e) {
    On to the next challenge...
    George

  • Formating string to date format in vc

    hai,
    function module in production return a date in type of char10. now i need to convert into proper data format.
    can any one help me.

    data: l_date type datum
          , l_d(10)
    l_date = sy-datum.
    write l_date to l_d. -> This statement will convert into user date format
    write:/ l_d.  
    ...Naddy

  • Business One date format question

    Hi,
    Business One formats dates coming out of the database as specified by the user.  But it looks like, when you set a date variable in your program code to the value coming out of the database and you set an edit text value to that variable, Business One doesn't format it.  Am I right?  I have a solution but I just want to make sure that there isn't something I'm missing.  I'm using VB .NET 2005.
    Thanks,
    Mike
    Edited by: Mike Angelastro on Jan 21, 2010 12:44 PM

    Vasu,
    Thanks for your suggestion.  I followed it but it doesn't seem to work.  The format appears to be more consistent with the machine's data format instead of what was specified in the general settings.  Here is my code:
    oDetailForm.DataSources.UserDataSources.Add("dsDueDate", SAPbouiCOM.BoDataType.dt_DATE)
    oEditText.DataBind.SetBound(True, , "dsDueDate")
    If Year(DueDate) > 1901 Then
             oEditText.Value = DueDate  'Format(DueDate, SystemDateFormat)
    Else
             oEditText.Value = "N/A"
    End If
    Is my code correct?
    Thanks again,
    Mike

  • JFileChooser and date format questions

    I have a JFileChooser that currently works - I set the default directory and allow the user to select a file or enter a file name.
    I have been asked to modify this to prepopulate the file name field on the JFileChooser.
    How do I do that? It is not obvious which method to call to set the filename field.
    Also, the file name needs to be a timestamp "*yyyyMMddHHmmss*.dat"
    I tried creating the timestamp part with the following code, but it does not format as expected.
            String s = "";
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddddHHmmss");
            try
                java.util.Date now = new java.util.Date();
                java.util.Date dat = dateFormat.parse( now.toString() );
                s = dat.toString();
            }What is wrong with this?
    Thanks.

    I don't do Swing and this is also not the subforum for Swing questions. It has its own subforum.

  • Function returning string.  Data type question

    Hello all,
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    Our database has a parent record master_member_record_id & and children of those records member_record_id. I wrote a function which returns the master record for the child.
    eg. get_master(member_record_id). simple enough.
    I have wrote the opposite of this also, get_member_records(master_member_record_id). Obviously this function has multiple records to return so I have it set to return a listagg string with ',' separation. They want to be able to use this function as follows:
    select * from member_table where member_record_id in (get_member_records(master_member_record_id));
    or something similar, I realize this is a data type issue here, wondering if this is even possible. What do you think?
    Thanks in advance for your criticism/help,
    Chris

    My disagreement is with how pipeline table functionality is used.
    Instead of this (what it sounds like the OP is doing but returning CSV format)
    create or replace type TClientIdArray is table of number;
    create or replace function GetClientIDs( parentID number ) return TClientIdArray is
      array TClientIdArray;
    begin
      select
        client_id bulk collect into array
      from master_table
      where parent_id = parentID;
      return( array );
    end;A pipeline would look as follows:
    create or replace type TClientIdArray is table of number;
    create or replace function GetClientIDs( parentID number ) return TClientIdArray pipelined is
    begin
      for c in (select
                   client_id
                 from master_table
                 where parent_id = parentID ) loop
        pipe row( c.client_id );
      end loop;
      return;
    end;The first method is in fact more sensible in this case, especially when used from PL/SQL. A single SQL call/context switch to get a list of client identifiers. The issues with the first method are
    - cannot effectively deal with a large data set of client identifiers
    - would be suboptimal to use this function in subsequent SQL
    - if called by a client, a ref cursor (not collection) should be returned
    But assuming that the list of client identifiers are needed to be stepped through via complex PL/SQL app processing, using a (small) array is fine (assuming that concurrency/locking is not needed via a FOR UPDATE on the select that identifies the client identifiers to process).
    A pipeline in this case does not do anything better. It introduces more moving parts - as a native PL/SQL can no longer be used to get the collection and step through it. A TABLE() SQL function is needed, a SQL statement, and more context switching.
    The pipeline is simply an unnecessary layer between the code wanting to use the client identifiers and the SQL statement supplying the client identifiers. This approach of SQL -calls-> PIPELINE -calls-> MORE SQL is invariable wrong - unless the pipeline (PL/SQL code) does something very funky with the data from its SQL call, prior to piping it, that cannot be done using SQL.
    If the "user" of that client identifiers is SQL code, then both the above methods are flawed. As this code is already SQL, why use PL/SQL to call more SQL code? Simply use the SQL code/logic that supplies the client identifier list directly in the SQL code that needs the client identifiers. This means something like SQL JOIN, EXISTS, or IN clauses.

  • Time Zone Offset - Date Format question

    I'm wondering if any one knows how to display the time zone offset of a date in the following format "[+-]HH:mm." More so... I need the date/time in the ISO 8601 format "yyyy-MM-dd'T'HH:mm:ss[+-]HH:mm", where the last [+-]HH:mm is the hour representation of the offset. Here's some sample code...
    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Calendar rightnow= Calendar.getInstance();
    // So if system date/time is February 14, 2002 at 1:15:00 PM EST, this would produce "2002-02-14T13:15:00"
    System.out.println("Current Datetime" + sdf1.format rightnow.getTime());
    How can I get the timezone offset appended to my output in a [+-]HH:mm format. So, the above date needs to look like "2002-02-14T13:15:00-05:00". I can get the offset in milliseconds by doing the following:
    int offset1 = rightnow.get(rightnow.ZONE_OFFSET) + rightnow.get(rightnow.DST_OFFSET);
    But how can you get this representation into the [+-]HH:mm format?
    thanks in advance,
    stophman

    Try something like this:import java.text.* ;
    import java.util.* ;
    static public String formatISO8601(Calendar cal) {
         * create ISO 8601 formatter for Calendar objects
        MessageFormat iso8601 = new MessageFormat("{0,time}{1,number,+00;-00}:{2,number,00}") ;
        // need to shove a date formatter that is cognizant of the
        // calendar's time zone into the message formatter
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") ;
        df.setTimeZone(cal.getTimeZone()) ;
        iso8601.setFormat(0, df) ;
         * calculate the time zone offset from UTC in hours and minutes at the current time
        long zoneOff = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET) ;
        zoneOff /= 60000L ;  // in minutes
        int zoneHrs = (int) (zoneOff / 60L) ;
        int zoneMins = (int) (zoneOff % 60L) ;
        if (zoneMins < 0) zoneMins = -zoneMins ;
        return (iso8601.format(new Object[] {
                                    cal.getTime(),
                                    new Integer(zoneHrs),
                                    new Integer(zoneMins)
    }

Maybe you are looking for