Translating a date format in a filename string

Hi,
Basically I have a property like:
filename=MyFile(yyyy-MM-dd@HHmmss).logWhen I create the file I want to translate the embedded date format string using the current date.
My solution is as follows:
   private static void createFile(String fName) {
      String[] fNameArray = new String[3];
      int openBracket = fName.indexOf("(");
      int closeBracket = fName.indexOf(")");
      // Split the file name into prefix, text inside brackets ie to be tranlated to a date and suffix
      fNameArray[0] = fName.substring(0, openBracket+1);
      fNameArray[1] = fName.substring(openBracket+1, closeBracket);
      fNameArray[2] = fName.substring(closeBracket);
      String dateFormat = fNameArray[1];
      DateFormat df = new SimpleDateFormat(dateFormat);
      String date = df.format(new Date());
      fNameArray[1] = date;
      fName = fNameArray[0].concat(fNameArray[1].concat(fNameArray[2]));
      ...This seems a little long winded to me (it works though). Does anyone know of a simpler way to code this?
Many Thanks

I've been looking around and came across String.format() which can be used to format strings using substitutions variables.
This works a treat but I must admit the property now looks a bit complex!
   String fName = "MyFile_%1$tY%1$tm%1$td%1$tH%1$tM%1$tS.log";
   fName = String.format(fName, Calendar.getInstance());
   // fName = MyFile_20060803132200.logThanks for your help.

Similar Messages

  • Need to rename files parsing date formats in the filename [SOLVED]

    Godaddy changed the naming scheme of their server logs again.  I need some perl or something magic that will convert format A to format B.  Doing this is bash is going to be painful so I'm hoping some of your perl or python ninjas out there could help me.
    format A:  ex20140425000001.log
    format B: Wed, May 21, 2014.log
    So for the example above, that date needs to be converted to this name: ex20140521000001.log
    Thanks in advance!
    EDIT: nevermind... forgot about date.
    #!/bin/bash
    for i in *.log; do
    fixeddate="$(echo $i | sed -e 's/,//g' -e 's/^....//' -e 's/.log//')"
    useitdate="$(date -d "$fixeddate" +%Y%m%d%H%M%S)"
    newname="ex$useitdate.log"
    mv "$i" "$newname"
    done
    Last edited by graysky (2014-06-07 09:41:59)

    sempervirent,
    You're asking for some pretty advanced file naming. Most people aren't going to need that sort of function, so I doubt there will be a hook into Aperture to do such a thing. I suggest using a shell script or Applescript along with EXIFTool to rename files before you import them into Aperture. http://www.sno.phy.queensu.ca/~phil/exiftool/
    Retain the unique number that the image already has
    If you're not afraid of the command line, it's easy enough to use a tool like awk or maybe perl to parse that sequence number from a well-formatted string like the picture name
    Replace "DSC" with the camera model (D3X)
    You can use EXIFTool to extract the camera model from the EXIF dat ain the photos
    Add a digit prior to the four-digit string to indicate the true numeric sequence of the file.
    Good luck with this one. You'll have to do a filename search through all of your previous files to find out what 10,000 you're on. It's possible, but you'd have to do some specialized coding in AppleScript or shell script.
    nathan

  • 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;
    }

  • String conversion gives error when converting to date format

    Hello,
    I need to convert a character to a date format. The character string is 201053131415151 where the first eight characters represent YYYYMMDD. The string may also be null ( second value). I used the following select statement
    select distinct sysdate "Run Date",
    rcreviewdate "Review Date",
    nvl((to_char(substr(rcreviewdate,1,8))),'None') "Review Date2"
    and got the following result.
    Run Date Review Date Review Date2
    30-NOV-09 201005131415151 20100513
    30-NOV-09
    1. Why is "None" not returned for the secord valule which is null?
    2. How can the valule "20100513" be converted to DD-MON-YY ( the date format)?
    to_date(substr(rcreviewdate,1,8),'YYYYMMDD') gives the following error with the null value
    Error report:
    SQL Error: ORA-01841: (full) year must be between -4713 and +9999, and not be 0
    01841. 00000 - "(full) year must be between -4713 and +9999, and not be 0"

    Hi,
    PANY wrote:
    1. Why is "None" not returned for the secord valule which is null?
    2. How can the valule "20100513" be converted to DD-MON-YY ( the date format)?
    to_date(substr(rcreviewdate,1,8),'YYYYMMDD') gives the following error with the null value
    Error report:
    SQL Error: ORA-01841: (full) year must be between -4713 and +9999, and not be 0
    01841. 00000 - "(full) year must be between -4713 and +9999, and not be 0"Are you sure reviewdate is NULL, and not a string consisting only of spaces or tabs?
    TO_DATE will return NULL if its 1st argument is NULL, so it looks like reviewdate is not NULL.
    You can use LTRIM (among other functions) to remove spaces from reviewdate, if that's the problem.
    Post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data.

  • Problems in the date format

    Hi,
    I am working on a program in which i retrieve date fields from an Oracle 8 DB & need to execute other db statements.The extracted date field's format is however different from that of Oracle format.Is there some way of obtaining the date fileld in the original format.(i am using jdbc-odbc bridge for the connection)
    Also can i change the format of the date field(in terms of mm-dd-yy etc) in java.

    Hi,
    to convert a JAVA date to some format, you can use java.text.DateFormat. Instead of using this rather complex class, you may also use java.text.SimpleDateFormat, which can translate a date according to a pattern string.
    What you get from your database may be a java.sql.Date object, right? This is a subclass of java.util.Date. It does not imply any specific text representation. The toString method simply uses yyyy-mm-dd. But with the DateFormat-classes, you can convert it to (almost) any other textual representation.

  • How to convert date format(mm/dd/yy) into dd-mm-yy

    I want to convert date format(mm/dd/yy) into dd-mm-yy
    like 12/23/06 into 23-sep-06

    hey, you can use SimpleDateFormat to format your date. this is sample code, maybe could help you.
    class dateFormat
         public static void main(String[] args)
              Date now = new Date();
              System.out.println("Before format : "+now);
              SimpleDateFormat sdf = new SimpleDateFormat( "dd-MM-yy" );//Change your date format in here.
              String display = sdf.format(now);
              System.out.println("After format : "+display);
    }If you already understand about my sample code, i think it's easy to make your own date format. Just modified few line of my code.

  • How to convert a String("yyyy-mm-dd") to the same but in Date format ?

    Hi,
    can anyone plz tell me how to convert a String to a date format.I'm using MSACCESS database.I want to store this string in the database.So i need to convert it to a date format since the table is designed such a way with date/time type for date field.I used SimpleDateFormat ,but i can't able to convert.The code is given below:
    coding:
    public String dateconvertion(String strDate)
    try
    SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdfSource.parse(strDate);
    SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd ");
    strDate = sdfDestination.format(date);
    catch(ParseException pe)
    System.out.println("Parse Exception : " + pe);
    return(strDate);
    }

    i used prepared statement even now i am getting error like this.....
    i have included the prepared statement package also...
    my coding:
    ResultSet rsdatetemp = null;
    PreparedStatement ps = null;
    String query ="select distinct itemcode from sales where bill date between ? and ?";
    ps = precon.prepareStatement(query);
    ps.setDate(1,d1);//d1 and d2 are in date format
    ps.setDate(2,d2);
    rsdatetemp = ps.executeQuery();
    error :
    symbol : method setDate(int,java.util.Date)
    location: interface java.sql.PreparedStatement
    ps.setDate(1,d1);
    symbol : method setDate(int,java.util.Date)
    location: interface java.sql.PreparedStatement
    ps.setDate(2,d2);

  • 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());

  • How to get the system date format string?

    Hello, everybody!
    I want to create a MaskFormatter with a mask for dates. So, I could suply as the constructor parameter: "##/##/####'. However, what if the year comes first in the current system date format settings, or the month is in the second place or in the first?... So, I can't just suppose that the current locale format for dates is like the one above. So, my question is: is there a way to get the SYSTEM DATE FORMAT STRING in Java? Searching in google I saw that this was already asked in this forum:
    http://forum.java.sun.com/thread.jspa?threadID=301034&messageID=1193794
    but there was no effective answer. Does someone already know how to get this?
    Thank you.
    Marcos

    Hi, not sure, but
    import java.text.*;
    SimpleDateFormat sdf = new SimpleDateFormat();
    System.out.println(sdf.toPattern());
    will output something like dd/MM/yy HH:mm
    hthThank you very much. It worked.

  • I18n for custom date format strings

    I want to internationalize dates shorter than DateFormat.SHORT, in the form "M/d". For example, when the Locale is US, January 16 should display as 1/16, but if the Locale is MX (Mexico), it should display as 16/1.
    It seems like a very simple problem date formatting problem, but it doesn't look like the DateFormat/SimpleDateFormat classes have any way of doing this. Am I missing something?
    --Steven                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    You need to apply your own customized date pattern to get the formats you want. I suggest you put the patterns in resource bundles...the default pattern in your default bundle, and the Mexican pattern in your bundle for Mexico. Then do something like this:
    <pre>
    <code>
    String newPattern = "M/d"; // retrieve from bundle instead
    Date today = new Date();
    DateFormat df = DateFormat.getInstance();
    SimpleDateFormat simpleFormat = (SimpleDateFormat)df;
    simpleFormat.applyPattern(newPattern);
    System.out.println(df.format(today);
    </code>
    </pre>

  • 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...

  • ORA-01830: date format picture ends before converting entire input string at OCI call OCIStmtFetch

    Hi all,
    We are trying to create a BIP Data Model based on an Answer, but after selecting report, it hangs when I try to Apply to create a query based on Oracle BI. When I try to open the query in aswers, going to results tab I'm getting this error (OBIEE 11.1.1.6.2):
    ORA-01830: date format picture ends before converting entire input string at OCI call OCIStmtFetch
    I suppose that BIP data model is not able to create it because of this error. But this answer is working fine inside dashboards, etc. It only does not work when editing it. Query is doing something like this: "USING "- Collection Attributes"."Due Date" >= TIMESTAMPADD(SQL_TSI_DAY, -30, CAST ('01/04/2009' AS DATE))"
    Any ideas?

    Solved watching date format in generated SQL and changing default date format in presentation variables default values inside criteria according to SQL format.

  • Using default application date format substitution string

    I'd like to reference something like ":app_default_date_format" to set date formats in sql statements.
    Does a substitution string exist that returns the default application date format?
    Thanks,
    -Ken

    Hello Ken,
    >> I'd like to reference something like ":app_default_date_format" to set date formats in sql statements.
    Isn’t the whole point of defining an application date format to avoid the need to specifically reference date formats?
    >> Does a substitution string exist that returns the default application date format?
    I’m not familiar with an official substitution string for the application date format but you can use wwv_flow.g_date_format .
    Regards,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    &diams; Author of Oracle Application Express 3.2 – The Essentials and More

  • Date Format Picture ends before converting entire input string..

    Hi all
    i am creating a report in 10g.. in which i want to convert Emp_lump_sum (number)  to character .I have created a formula column in which i have written a function in the formula column and assign that formula column to the text field in which i want the result.
    when the report run i get the following error....
    ORA-01830: date format picture ends before converting entire input string..
    i have tried with a attribute EMP_NO (Varchar2(30)), it shows the result but when i add EMP_LUMP_SUM (NUMBER) , it show the above error. on the database side i get the same error.
    Database : 11g
    OS :     Windows server 2003
    reports   : 10g
    any help will be thankful..
    Function i wrote behind the formula coloumn is..
    function CF_1Formula return CHAR is
    xy varchar2(100);
    begin
      select to_char(to_date(emp_lump_sum,'j'),'jsp') into xy from fms_111_form4_tr;
        return xy;
        --xy := f_19;
    end;

    Hello:
    Try to use a database function and call it from reports.
    Regards,

  • 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?

Maybe you are looking for

  • How do I share an external drive between OSX 10.3 and 10.5?

    My setup is a external drive (FAT) connected via firewire to an ibook g3 using OSX10.3. I have installed sharepoints on that mac. Now, I can see and use the ibook g3 share on my ibook g4 using OSX10.5 , but not the external drive. I can access the dr

  • Script to insert an existing Rich symbol throws error

    I have an existing Rich Symbol called RSymbol. Now I write a script to place RSymbol into a certain layer which create. The problem is, that everytime i import a symbol like this with fw.getDocumentDOM().importFile(fw.appSymbolLibrariesDir+"RSymbol.g

  • Sort by Alias name in Webform

    Hi All, Greetings!!! I have defined employee dimension as row in Webform and display property as "Alias". Now the requirement is, I need to display the employees based on sort by their alias names. Thank you so much for your kind help Regards, tvmk

  • Using IF in a for each loop which is grouped by two fields

    Hi , My requirement is to filter the Payment records ,based on the parameter input date and also group by based on two of the Fields and calculate the sum of the payment Amounts. I have created a for each loop with the group by first on one field and

  • Multiple Login in ATG on multiple server instances.

    Hi, I'm facing a issue with multiple logins in my web application. The scenario is explained below: 1. I login from one browser (IE) and add an item to cart. Then I navigate to cart page. I logout. 2. I login from another browser (Chrome) and add ano