Formatting: String > Date > String

This is the best I could do, how to simplify this:
value = new SimpleDateFormat("MMM dd, yyyy  HH:mm:ss").format((java.util.Date)new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value.toString()));

NKA says:
>
The idea behind exceptions, is that you assume each step will work, and just write the code as if it does. If the method I call returns null instead of throwing an exception on failure, then I have to explicitly check for null at this point, rather than simply move on to the next step. With some exceptions, I know that if I even got to that next step, then nothing was wrong.
>

What is this means that the calling code must know that there is an exception thrown from code that was called?

Well, Yes, if you call a method, and something goes wrong, you want to know about it, right? Catch the exception does not solve anything. All that's happened is always false. You catch an exception because you plan to do something about this.

What I understand from what you said that the operation should fill in some way by throwing an exception back to the caller, and then, the caller must decide what to do with it.

Exactly. And often - most of the time, in fact - that the appellant made with it will just continue to throw on top of the stack to its calling.

What I do is that logs the error in the file and show a popup error message to the user. It works as the operation has not completed, so got canceled due to the outbreak of the exception.

If you are at a high enough level layer of your code, which may be appropriate. However, I prefer to see this:

try {
  formatDate();
}
catch (SomeException e) {
  showErrorMessageDialog();
}

than that:

String s = formatDate();
if (s == null) {
  showErrorMessageDialog();
}

Tags: Java

Similar Questions

  • problems by analyzing a date format string...

    Hi all, I'm having a hard time to convert a date into a string.

    I was using to_char but after much research, I thought that it would be better to use convert so I do:

    SELECT CONVERT (VARCHAR (8), 'November 19, 2012', 112) twice;

    Where the specifications for 112 is YYYYMMDD but I get the error "ORA-00936: lack of expression ', guess is cause Oracle do not know how to read the string to be converted.

    How can I convert a YYYYMMDD string format string of the form dd mmm yyy (as described above)?

    Thanks in advance,

    It seems that your search will lead you to a SQL Server thread. SQL Server uses arbitrary numbers to represent date formats. Oracle does not - the number 112 is irrelevant for Oracle.

    In Oracle, you convert a date to a string using the function TO_CHAR

    SELECT to_char( date '2012-11-19', 'YYYYMMDD' )
      FROM dual
    

    Of course, this assumes that you start with a date (like I do with my date literal). If you start with a string representing a date and you want to convert it to a string that represents the same date in a different format, you will need to use a TO_DATE and a TO_CHAR to convert the original string to a date and date on another string

    SELECT to_char( to_date( '19 Nov 2012', 'DD Mon YYYY' ), 'YYYYMMDD' )
      FROM dual
    

    Justin

  • Getting ORA-01861: literal does not match format string whith 2 passes DATE

    Not exactly a complete Newbie, but not an expert either but it left me speechless...

    I have two DATE columns in two different tables.
    In a select statement I compare these two in the where clause.

    ... and
    Table1. Column1 = table2.column1

    I then get

    ORA-01861: literal does not match the format string (and toad has highlighted the second column)

    I made a selection on the two tables to have a look at the values and found that, the values in a table (Toad), has this format: YYYYMMDD but in the other select table produces a column of values in the format YYYY-MM-DD

    I've made a desc on the two paintings and confirmed that the two are DATE columns...

    I've never seen different date formats in the same database... Thinking about it now (I'm home and can not verify) the two tables could be in different schemas... Different schemas can display different date formats?

    In any case, I tried to_date ([column] on the two (in the where clause) and got that a nonnumeric value has been found where a numeric value has been planned (this time for the first column).)

    So I guess I ask how come two different date formats and how to find the nonnumeric value in table 1 which contains lines of 5.8 million

    Any tips/ideas/tips?

    Please check back when you get back to work... I can almost guarantee you that one (if there is not both) of these columns is NOT a data type DATE (or timestamp).

    Or if they are, you are actually handled in a view or query to convert to this type of data.

  • BUG: Date/Time Format string with %D in the format string crashes LabVIEW

    Do %D in the format string 'Format string DateTime' blocks LabVIEW 2009 SP1, as shown in this code snippet.  Should I use instead of %D %d but an incorrect format string should not crash LabVIEW.

    Fixed in 2010.

  • format string IF (always kHz)

    Hello

    I'm reading values from rates to sample different RF bands DBL and using the value to create a file header to store binary data complex 32IQ to the file. I use the format based on string to do, but I still want to be represented in kHz, the sampling frequency and I have not thought of a way to force it is always the case. I use a format string of %.3p which, for sampling rate as 13125 and 400000 he returns 13,125 k and 400,000 k respectively, and that's what I want. However, one of my groups is 3750000 Hz and the format to a string returns Mr. 3,750, I would come back 3750,000 k instead. Does anyone have any ideas on how I might accomplish this?

    Thank you

    Tim

    If you divide the value by 1000 dbl and then apply the format to a string with the specifier %.3f you the kHz value.

    Ben

  • Unit to the Format string

    Hi all

    If a control already has a unit, and move us to a format based on the string, its does not display is not the same exact unit. For example, under control has 'g' unit, while the format string has unit "kg".

    1. Is it possible to do the format to a string take the exact unit specified in the control?
    2. Is there a way to delete unit in the format based on the string, even if the digital order entry has a specified unit?

    Attachment VI to 2010.

    Thank you

    Knockaert

    Not automatically, no. The problem is that the designation of the unit in effects only control how data is displayed in a particular control. When wire you a value with units in a format to the node of the chain, it will express the value of the base unit for the wire.

    Mike.

  • literal does not format string when collecting in bulk.

    Hello
    should work with 10.2 DB.
      1  declare
      2    type vcArray is table of varchar2(10);
      3    type vdateArray is table of date;
      4    l_group#   vcArray;
      5    l_status vcArray;
      6    l_date vdateArray;
      7    cursor c is select to_char(sysdate, 'YYYYMMDD_HH24MISS') data, GROUP# , status from v$log;
      8  begin
      9  open c;
     10  loop
     11     fetch c bulk collect into l_date, l_group# , l_status;
     12     for i in 1..l_date.count
     13     loop
     14      dbms_output.put_line('l_date: ' || l_date(i));
     15     end loop;
     16     exit when c%notfound;
     17  end loop;
     18  close c;
     19* end;
    declare
    *
    ERROR at line 1:
    ORA-01861: literal does not match format string
    ORA-06512: at line 11
    Just try to display loop a few output of v$ log view :).
    Concerning
    GregG

    Hello

    GregG says:
    Hello
    should work with 10.2 DB.

    1  declare
    2    type vcArray is table of varchar2(10);
    3    type vdateArray is table of date;
    4    l_group#   vcArray;
    5    l_status vcArray;
    6    l_date vdateArray;
    7    cursor c is select to_char(sysdate, 'YYYYMMDD_HH24MISS') data, GROUP# , status from v$log;
    8  begin
    9  open c;
    10  loop
    11     fetch c bulk collect into l_date, l_group# , l_status;
    12     for i in 1..l_date.count
    13     loop
    14      dbms_output.put_line('l_date: ' || l_date(i));
    15     end loop;
    16     exit when c%notfound;
    17  end loop;
    18  close c;
    19* end;
    declare
    *
    ERROR at line 1:
    ORA-01861: literal does not match format string
    ORA-06512: at line 11
    

    Just try to display loop a few output of v$ log view :).
    Concerning
    GregG

    To_char, as the name suggests, returns a VARCHAR2, c.data is therefore a VARCHAR2, but you try to store it in an array of DATEs.
    Do not use TO_CHAR. In fact, there is no need to use a column for that at all, because SYSDATE will always be the same.

    Try something like this:

    declare
        type vcArray is table of varchar2(10);
        l_group#   vcArray;
        l_status vcArray;
        cursor c is select GROUP# , status from v$log;
        run_time DATE;
      begin
      open c;
      loop
         run_time := SYSDATE;
         fetch c bulk collect into l_group# , l_status;
         for i in 1..l_group#.count
         loop
          dbms_output.put_line('run_time: ' || run_time);
         end loop;
         exit when c%notfound;
      end loop;
      close c;
    end;
    /
    

    Published by: Frank Kulash on 12 March 2012 10:26
    Added example.

  • SQLERRM: ORA-01861: literal does not match the format string

    Here's what I want to do.

    Select to_char (to_date (estimatedshipdate, 'DD-MM-AA'), 'YDDD')
    of cram_stg
    where estimatedshipdate = 14 January 11 ';

    TO_CHAR (TO_DATE(ESTIMATEDSHIPDATE,'MM-DD-YY'), 'YDDD')
    -----------------------------------------------------
    1014


    1 selected lines


    I want to convert the shipping date is DD-MM-AA YDDD, but in my program:

    v_est_ship_date varchar2 (10);

    ESTIMATEDSHIPDATE VARCHAR2 (10) in a TABLE

    v_est_ship_date: = to_char (to_date (CRAM_PTCLICK_REC.estimatedshipdate, 'DD-MM-AA'), 'YDDD');

    I get this problem

    SQLERRM: ORA-01861: literal does not match the format string


    I want to assign the result of the function to_char to v_ext_ship_date. What I am doing wrong? Thank you.

    Hello

    It's just one of the reasons for which the storage of dates as VARCHAR2 columns is a bad idea.
    Apparently, some (maybe just one) this column values is not the right format. To find malformed (the kind that cause the ORA-01861) values, you can do something like this:

    SELECT  primary_key
    ,     estimatedshippingdate
    FROM     cram_stg
    WHERE     TRANSLATE ( estimatedshippingdate
                , '012345678'
                , '999999999'
                ) != '99-99-99'
    ;
    

    It intercepts any mistakes as the 32nd day of the month (let alone ' 02-29-11'). See the next thread of a way to do this:
    Re: How to select valid dates only

  • Failed to run backup using the format string

    Hi all

    Need help with RMAN, my problem as below:

    RMAN > run {}
    2 > level 1 incremental backup cumulative
    3 > format "D:\ora\rmanbackup\RCKLGC_INC < % s: T: %p % _ > .dbf.
    4 > tag data base 'DAILY_DATAFILES ';
    {5 >}

    From backup 29 June 09
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID = 145 type device = DISK
    channel ORA_DISK_1: starting from compressed data file backup set incremental level 1
    channel ORA_DISK_1: specifying datafile (s) in the backup set
    Enter a file 00005 name = E:\ORA\ORADATA\RCKLGC\MGMT = datafile number. DBF
    Enter a file name 00002 = E:\ORA\ORADATA\RCKLGC\UNDOTBS01 = datafile number. DBF
    Enter a file name 00006 = E:\ORA\ORADATA\RCKLGC\MGMT_ECM_DEPOT1 = datafile number. DBF
    Enter a number of file datafile = 00001 name = E:\ORA\ORADATA\RCKLGC\SYSTEM01. DBF
    Enter a number of file datafile = 00003 name = E:\ORA\ORADATA\RCKLGC\SYSAUX01. DBF
    Enter a file name 00007 = E:\ORA\ORADATA\RCKLGC\DATAFILE\O1_MF_RMAN_DAT_4M9QWZT5_ = datafile number. DBF
    Enter a number of file datafile = 00004 name = E:\ORA\ORADATA\RCKLGC\USERS01. DBF
    channel ORA_DISK_1: starting piece 1 to 29 June 09
    RMAN-00571: ===========================================================
    RMAN-00569: = ERROR MESSAGE STACK FOLLOWS =.
    RMAN-00571: ===========================================================
    RMAN-03009: failure of the backup command on the channel ORA_DISK_1 at 2009-06-29 18:20:49
    ORA-19504: cannot create the file '< _1097:20090629:1 > D:\ORA\RMANBACKUP\RCKLGC_INC. DBF. "
    ORA-27040: create file error, cannot create the file
    04002 - OSD: could not open the file
    S/O-error: (123 OS) the file name, directory name or volume label syntax is incorrect.

    ----------------------------------------

    If I set the format by default %U work string. Can someone help me? The sting of format I used on the database under Linux works fine without any problems.

    Hi faisal.badrom,
    Can you be more specific on the 'format string to meet backup requirement standards "?
    Are you allowed to jump ">".< :"="">
    If you can use:

    format 'D:\ora\rmanbackup\RCKLGC_INC_%s_%T_%p.dbf '.

    Or to extend it again with the name of the database:

    format 'D:\ora\rmanbackup\RCKLGC_INC_%s_%T_%p_%d.dbf '.

    to meet the standard?

    Kind regards

    Tycho

    Edited by: tychos on June 30, 2009 01:33

  • formatted string

    I have different strings in my project, for example:

    12.4432615352312

    I want that all these channels have 2 decimal places, so 12.44; How can I do this? I was looking for 'Format value function' and also 'format as string' (format string), but without success.

    Thank you

    Here's a very easy way

    Although there is probably a method using reg expressions without the intermidiatry changing double.

    Craig

  • Digital format in 0.000E + 0 in format string

    How to format a digital DBL double 0.000E + 0-shaped, functional screws?

    Do I need a REGEX for string format?

    Thank you

    Alan

    saintalan94 wrote:

    How to format a digital DBL double 0.000E + 0-shaped, functional screws?

    You just need 'in Format string' function with the correct entry of STRING of FORMAT .

  • chain number by "scan value" format string "%.3f" doesn'work

    I had a little problem.

    "To convert a string to a number, I use the function"scan value"with '%.3f' for the ' format string"connector. I would get a 3 digit number. But this doesn't work with the parameter "%.3f.

    Thank you.

    Please check the syntax of using LV Format specifier. There is a table that describes the purpose of each specifier. When you read in the description "when you use a function in shape", the specifier is applied to the number-> string, when you read "when you use a sweep feature", the specifier applies to the String-> number. The syntax of width element applies to both situations, the. Element of syntax accuracy does not work.

  • Hexadecimal format string

    Hello

    This is a really easy question, but I want the final string to have only the first two digits (cut on all 0). I can't understand what is appropriate to use format string...

    Thank you

    In fact, instead of the string, right click the "zero" constant that you use to change the format and choose 'Représentation--> U8' and it is probably the best way of trimming.

    Basically, a letter is a byte and the constant zero you have there an I32, which is 4 bytes, generates the extra 6 zeros.

  • How can we force to use for locale-specific formatting of data?

    Hi all

    I use the Date/Time Format string to format the current date to a formatted string, I'm precise %b to show the short month, but this parameter is dependent on the local host. What is a way to force the format on a local data instead of using the regional settings of the OS? Thank you.

    I don't believe it. The simplest solution would be to call the DateTime in seconds function, extract the resulting month value of the cluster then use a lookup table to determine the name of the month.

    The table of correspondence could be as simple as a multiline string is indexed with the Line Pick function using months as the row index.

  • How to format the data back of JMX

    I want to fomat dates back to JMX on foglight Server (5.6.5).

    "Ex: convert date format 'long' ' String (PST).

    Also, can I format the data on the dashboard in a different format?

    Ex: Covert "MM/DD/YYY" to "DD-MM-YY".

    I am unable to make use of 'Deriverd' but you need to know if it is possible for data formatting with out creating "Derived Metrics"

    Thank you.

    As usual, in Foglight, there are several ways of doing things, and most things are possible.

    Remember that the date you see is probably not a string format, but a java rendering Date (similar to what you see) or Timestamp objects.

    What you are looking for on a dashboard is a different rendering engine, an object that converts the presentation of the data from one format to another.

    There are many kinds of converters that come with Foglight, including fully customizable Date converters.

    The model on a Date Converter personal property can be used to do almost anything.

  • Dynamically change the Format of Date of Application

    Hi all

    I am looking for a possibility to change the format of date of Application in globalization attributes dynamically according to the user.

    Something likeAPEX_UTIL.SET_SESSION_TIME_ZONE but for the date format.

    Does anybody know how it works?

    In detail:

    I want dates in interactive reports display in a specific date format.

    If I put the following in the attributes of 'security' - call the virtual private database PL/SQL to define the security context:

    BEGIN

    If password = "MY_TEST_USER" then

    run immediately "alter session set nls_calendar =" English Hijrah "';"

    run immediately "alter session set nls_date_format =" DD-MM-YYYY "';"

    end if;

    END;

    Then, the dates are indicated correctly in reports interactive but not in the Action menu-> filter.

    If I put date_format = "DD-MM-YYYY" in the attributes of the globalization, it works very well in the interactive report filter.

    The problem is that I want to set this attribute only for some users.

    Thank's,

    Kirsten

    (APEX 4.0/APEX 4.2)

    Because you can use string syntax of substitution for the attributes of the globalization, for example, you could create an element of the AI_DATE_FORMAT application, reference & AI_DATE_FORMAT. and fill out the application element according to certain parameters in the code after the authentication of the authentication system (for example: get a parameter of an array of parameters user or somesuch).

Maybe you are looking for

  • motherboard not worknig

    iPhone 6 does not, perhaps due to motherboard problem. What will be the next step?

  • Satellite Pro 4600 PS460E turns off in 3-4 minutes after the connection

    My Toshiba laptop is having problem that it turned off after 3-4 minutes of connection. He doesn't get turned off when we run it in safe mode.Pls let me know how to troubleshooting this problem.

  • How to remove FCP7 rendering files, using FCPX or Finder

    Hello I am trying to eliminate unnecessary files.  For any project FCPX, I see that there is a process to remove the render files.  But what I do with projects created in FCP7?  These are projects which have had their XML files imported for use in FC

  • Pavilion dv7 - 1247cl: upgrade memory dv7 - 1247cl

    It is my understanding that my Pavilion dv7 - 1247cl can support up to 8 GB memory max.  The laptop will support a 8gig stick, or should it be 2 4 gig sticks?  In addition, if it supports a key of 8 GB, the memory would work faster compared to the tw

  • Windows 7 XP

    Hello.. My question is... Windows 7 comes normally with it's own Java Michine?... If so, what is the name of her ask so I can check if it is already installed... I recently had my deleted computer clean and the Tech Guy installed Oracal Java on my co