Parsing stopwatch data

I need to parse stopwatch data from a textfile in a beautifull way.
Data is represented in a "5.25.12" way, where 5 stands for 5 minutes, 25 stands for 25 seconds and 12 stands for 120 milliseconds.
Is there a way to parse such a date with a SimpleDateFormat?
I tried to do so using "mm.ss.SSS" pattern, but failed (result was a negative value).
1) is it possible to parse "5.25.12" data by using SimpleDateFormat?
1a) which pattern should I use to parse such a string to date?
2) May be there is a more beautiful way to parse such a data?
Message was edited by:
Nikita_Koselev

The pattern you give is valid and using it you can construct a SimpleDateFormat which will convert a String like "5.25.12" into a date whose toString() representation is like "Thu Jan 01 00:05:25 NZST 1970".
Note: you get 12 milliseconds, not 120. If your data records centiseconds you may have to add a zero. Also it does give a date. If you are more interested in an interval of time you could split() the string and use the components separately.

Similar Messages

  • Script for parsing xml data and inserting in DB

    Thank you for reading.
    I have the following example XML in an XML file. I need to write a script that can insert this data into an Oracle table. The table does not have primary keys. The data just needs to be inserted.
    I do not have xsd file in this scenario. Please suggest how to modify Method 1 https://community.oracle.com/thread/1115266?tstart=0 mentioned so that I can call the XML mentioned below and insert into a table
    Method 1
    Create or replace procedure parse_xml is 
      l_bfile   BFILE; 
      l_clob    CLOB; 
      l_parser  dbms_xmlparser.Parser; 
      l_doc     dbms_xmldom.DOMDocument; 
      l_nl      dbms_xmldom.DOMNodeList; 
      l_n       dbms_xmldom.DOMNode; 
      l_file      dbms_xmldom.DOMNodeList; 
      l_filen       dbms_xmldom.DOMNode; 
      lv_value VARCHAR2(1000); 
       l_ch      dbms_xmldom.DOMNode; 
    l_partname varchar2(100); 
    l_filename varchar2(1000); 
      l_temp    VARCHAR2(1000); 
      TYPE tab_type IS TABLE OF tab_software_parts%ROWTYPE; 
      t_tab  tab_type := tab_type(); 
    BEGIN 
      l_bfile := BFileName('DIR1', 'SoftwareParts.xml'); 
      dbms_lob.createtemporary(l_clob, cache=>FALSE); 
      dbms_lob.open(l_bfile, dbms_lob.lob_readonly); 
      dbms_lob.loadFromFile(dest_lob => l_clob,    src_lob  => l_bfile,    amount   => dbms_lob.getLength(l_bfile)); 
      dbms_lob.close(l_bfile);  
      dbms_session.set_nls('NLS_DATE_FORMAT','''DD-MON-YYYY'''); 
      l_parser := dbms_xmlparser.newParser; 
      dbms_xmlparser.parseClob(l_parser, l_clob); 
      l_doc := dbms_xmlparser.getDocument(l_parser); 
        dbms_lob.freetemporary(l_clob); 
      dbms_xmlparser.freeParser(l_parser); 
      l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),'/PartDetails/Part'); 
        FOR cur_emp IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP 
        l_n := dbms_xmldom.item(l_nl, cur_emp); 
        t_tab.extend; 
        dbms_xslprocessor.valueOf(l_n,'Name/text()',l_partname); 
        t_tab(t_tab.last).partname := l_partname; 
        l_file := dbms_xslprocessor.selectNodes(l_n,'Files/FileName'); 
        FOR cur_ch IN 0 .. dbms_xmldom.getLength(l_file) - 1 LOOP 
          l_ch := dbms_xmldom.item(l_file, cur_ch); 
          lv_value := dbms_xmldom.getnodevalue(dbms_xmldom.getfirstchild(l_ch)); 
          if t_tab(t_tab.last).partname is null then t_tab(t_tab.last).partname := l_partname; end if; 
          t_tab(t_tab.last).filename := lv_value; 
        t_tab.extend; 
       END LOOP; 
       END LOOP; 
        t_tab.delete(t_tab.last); 
      FOR cur_emp IN t_tab.first .. t_tab.last LOOP 
      if t_tab(cur_emp).partname is not null and  t_tab(cur_emp).filename is not null then 
        INSERT INTO tab_software_parts 
        VALUES 
        (t_tab(cur_emp).partname, t_tab(cur_emp).filename); 
        end if; 
      END LOOP; 
      COMMIT; 
      dbms_xmldom.freeDocument(l_doc); 
    EXCEPTION 
      WHEN OTHERS THEN 
        dbms_lob.freetemporary(l_clob); 
        dbms_xmlparser.freeParser(l_parser); 
        dbms_xmldom.freeDocument(l_doc); 
    END; 
    <TWObject className="TWObject">
      <array size="240">
        <item>
          <variable type="QuestionDetail">
            <questionId type="String"><![CDATA[30]]></questionId>
            <questionType type="questionType"><![CDATA[COUNTRY]]></questionType>
            <country type="String"><![CDATA[GB]]></country>
            <questionText type="String"><![CDATA[Please indicate]]></questionText>
            <optionType type="String"><![CDATA[RadioButton]]></optionType>
            <answerOptions type="String[]">
              <item><![CDATA[Yes]]></item>
              <item><![CDATA[No]]></item>
            </answerOptions>
            <ruleId type="String"><![CDATA[CRP_GB001]]></ruleId>
            <parentQuestionId type="String"></parentQuestionId>
            <parentQuestionResp type="String"></parentQuestionResp>
          </variable>
        </item>
        <item>
          <variable type="QuestionDetail">
            <questionId type="String"><![CDATA[40]]></questionId>
            <questionType type="questionType"><![CDATA[COUNTRY]]></questionType>
            <country type="String"><![CDATA[DE]]></country>
            <questionText type="String"><![CDATA[Please indicate]]></questionText>
            <optionType type="String"><![CDATA[RadioButton]]></optionType>
            <answerOptions type="String[]">
              <item><![CDATA[Yes]]></item>
              <item><![CDATA[No]]></item>
            </answerOptions>
            <ruleId type="String"><![CDATA[CRP_Q0001]]></ruleId>
            <parentQuestionId type="String"></parentQuestionId>
            <parentQuestionResp type="String"></parentQuestionResp>
          </variable>
        </item>
      </array>
    </TWObject>

    Reposted as
    Script to parse XML data into Oracle DB

  • How do you store parsed XML data in an array

    Hi, i am trying to complete a small program which implements the SAX parser to parse an XML file. My problem is that i am writing a custom class to store the parsed data into an array, and then make the array available to the main program via a simple method which returns the array. I know this must be very simple to do, but i seem to have developed a mental block with this part of the program. I can parse the data and print all the elements to the screen, but i just cant figure out how to store all the data elements into the array. I will post the class which is supposed to do this, and ask anyone out there if they know what i'm doing wrong, and also, if there is a more effeicient way of achieving this ( i expect there definitely is!! but i have never used the SAX parser before and am getting confused by the API docs on it!!) Any help very much appreciated.
    Here is my attempt at coding the class to handle the parsed XML data
    class Sink extends org.xml.sax.helpers.DefaultHandler
         implements org.xml.sax.ContentHandler{
    Customer[] customers = new Customer[20];
         int count = 1;
         int x = 0;
         int tagCount = 0;
         String name;
    String custID;
         String username;
         String address;
         String phoneNum;
    public void startElement(String uri, String localName, String rawName, final org.xml.sax.Attributes attributes)throws org.xml.sax.SAXException{
    //count the number of <name> tags in the XML file
         if(rawName.equals("name")){
              tagCount++;
    public void characters(char[] ch, int start, int len){
    //get the current string
         String text = new String(ch, start, len);
         String text1 = text.trim();
    //there are 5 elements for each customer found in the XML file so when the count reaches 6
    // i reset this to 1
         if(count == 6){
         count = count - 5;
         if(text1.length()>0 && count == 1){
              name = text1;
              System.out.println(name);
              }else{
         if(text1.length()>0 && count == 2){
              custID = text1;
              System.out.println(custID);
                   }else{
                   if(text1.length()>0 && count == 3){
                   username = text1;
                   System.out.println(username);
                   }else{
                        if(text1.length()>0 && count == 4){
                        address = text1;
                        System.out.println(address);
                        }else{
                        if(text1.length()>0 && count == 5){
                             phoneNum = text1;
                             System.out.println(phoneNum);
                             //add data to the customer array
                             customers[x] = new Customer(name, custID, username, address, phoneNum);
    // increment the array index counter
                        x = x+1;
                        }//end of if
                        }//end else
                        }//end else
                   }//end else
              }//end else
    }//end of characters method
    public void endDocument(){
         System.out.println("There are " + tagCount +
         " <name> elements.");
    }//end of class Sink
    Before the end of this class i also need to make the array available to the calling program!!
    Any help would be much appreciated
    Thanks
    Iain

    Ok, yer going about this all the wrong way. You shouldn't have to maintain a count of all the elements. Basically you are locking yourself into the XML tags not only all being there but are assuming they are all in the same order. What you should do is in your characters() method, put all of the characters into a string buffer. Then, in endElement() (which you dont use btw, you should) you grab the information that is in the string buffer and store it into your Customer object depending on what the tagName is.
    Also, you should probably use a List to store all the Customer objects and not an single array, it's more dynamic and you arent locked into a set number of Customers.
    I wont do it all for you, but I'll give you a good outline to use.
    public class CustomerHandler extends DefaultHandler {
        private java.util.List customerList;  // List of Customer objects
        private java.util.StringBuffer buf;   // StringBuffer to store the string of characters between the start and end tags
        private Customer customer;  // Customer object that is initialized with each entry.
        public CustomerHandler() {
            customerList = new java.util.ArrayList();   // Initialize the List
            buf = new java.util.StringBuffer();   // Initialize the string buffer
        //  Make your customer list available to other classes
        public java.util.List getCustomerList() {
            return customerList;
        public void startElement(String nsURI, String sName, String tagName, Attributes attributes) throws SAXException {
            // Clear the String Buffer
            //  If the tagName is "Customer" then create a new Customer object
        public void characters(char[] ch, int start, int length) {
            //  append the characters into the string buffer
        public void endElement(String nsURI, String sName, String tagName) throws SAXException {
            // If the tagName is "Customer" add your customer object to the List
            // Place the data from the String Buffer into a String
            //  Depending on the tagName, call the appropriate set method on your customer object
    }

  • Can't parse XML data

    I'm receiving an XML document over a TCP socket, I then instantiate an instance of DOMParser and attempt to parse the data. Here's the exception:
    org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x0) was found in markup after the end of the element content.
         at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1213)
         at org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError(XMLDocumentScanner.java:588)
         at org.apache.xerces.framework.XMLDocumentScanner$TrailingMiscDispatcher.dispatch(XMLDocumentScanner.java:1461)
         at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
         at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
    Here's the relevant snippet(s) of source (there is code to write out the socket, but I didn't include that)
    Socket socket = new Socket( hostIP, hostPort );
    OutputStream outStream = socket.getOutputStream();
    InputStream inStream = socket.getInputStream();
    DataInputStream dataInStream = new DataInputStream( inStream );
    byte[] inByteArray  = new byte[ 2048 ];
    int length =  dataInStream.read( inByteArray );
    InputStream byteData  =  new ByteArrayInputStream( inByteArray );
    try
           DOMParser dp = new DOMParser();
           dp.parse( new InputSource( byteData ));
           Document doc = dp.getDocument();
    catch ( Exception e )
            e.printStackTrace();
            System.exit( 1 );
    }Is there a different way to do this? I even tried creating a new String based on the length read from the socket, minus one. The parser then saw that the final angle bracket of my root element was missing, so it doesn't seem to be an encoding issue.
    Any help would be appreciated.
    Jeff

    An invalid XML character (Unicode: 0x0)The XML is corrupt.
    ...saw that the final angle bracket of my rootelement was missing,
    After you subtracted one from the length - that would
    suggest that not subtracting one would be a good
    idea.Yep. That was a test to verify that the data was in tact and not null terminated. To doubly check, I took an Ethereal trace of the wire, and there was no null. If I convert the byte[] to a String, everything is fine. Unfortunately,
    there wasn't a parser method that took the XML document as a String.
    >
    I would suppose that the real problem here has
    nothing to do with XML nor DOM but rather that you
    are not correctly retreiving the data from the socket.Data is fine from the socket, I just had to implement my own getAttribute() and getElementContent, and use brute force. I just thought using an already written parser made more sense.
    Thanks for the reply.

  • How to parse xml data into java component

    hi
    everybody.
    i am new with XML, and i am trying to parse xml data into a java application.
    can anybody guide me how to do it.
    the following is my file.
    //MyLogin.java
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    class MyLogin extends JFrame implements ActionListener
         JFrame loginframe;
         JLabel labelname;
         JLabel labelpassword;
         JTextField textname;
         JPasswordField textpassword;
         JButton okbutton;
         String name = "";
         FileOutputStream out;
         PrintStream p;
         Date date;
         GregorianCalendar gcal;
         GridBagLayout gl;
         GridBagConstraints gbc;
         public MyLogin()
              loginframe = new JFrame("Login");
              gl = new GridBagLayout();
              gbc = new GridBagConstraints();
              labelname = new JLabel("User");
              labelpassword = new JLabel("Password");
              textname = new JTextField("",9);
              textpassword = new JPasswordField(5);
              okbutton = new JButton("OK");
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 5;
              gl.setConstraints(labelname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 2;
              gbc.gridy = 5;
              gl.setConstraints(textname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 10;
              gl.setConstraints(labelpassword,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 2;
              gbc.gridy = 10;
              gl.setConstraints(textpassword,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 15;
              gl.setConstraints(okbutton,gbc);
              Container contentpane = getContentPane();
              loginframe.setContentPane(contentpane);
              contentpane.setLayout(gl);
              contentpane.add(labelname);
              contentpane.add(labelpassword);
              contentpane.add(textname);
              contentpane.add(textpassword);
              contentpane.add(okbutton);
              okbutton.addActionListener(this);
              loginframe.setSize(300,300);
              loginframe.setVisible(true);
         public static void main(String a[])
              new MyLogin();
         public void reset()
              textname.setText("");
              textpassword.setText("");
         public void run()
              try
                   String text = textname.getText();
                   String blank="";
                   if(text.equals(blank))
                      System.out.println("First Enter a UserName");
                   else
                        if(text != blank)
                             date = new Date();
                             gcal = new GregorianCalendar();
                             gcal.setTime(date);
                             out = new FileOutputStream("log.txt",true);
                             p = new PrintStream( out );
                             name = textname.getText();
                             String entry = "UserName:- " + name + " Logged in:- " + gcal.get(Calendar.HOUR) + ":" + gcal.get(Calendar.MINUTE) + " Date:- " + gcal.get(Calendar.DATE) + "/" + gcal.get(Calendar.MONTH) + "/" + gcal.get(Calendar.YEAR);
                             p.println(entry);
                             System.out.println("Record Saved");
                             reset();
                             p.close();
              catch (IOException e)
                   System.err.println("Error writing to file");
         public void actionPerformed(ActionEvent ae)
              String str = ae.getActionCommand();
              if(str.equals("OK"))
                   run();
                   //loginframe.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    hi, thanks for ur reply.
    i visited that url, i was able to know much about xml.
    so now my requirement is DOM.
    but i dont know how to code in my existing file.
    means i want to know what to link all my textfield to xml file.
    can u please help me out. i am confused.
    waiting for ur reply

  • Parsing the data from and xml type field

    Hi - I have registered a schema and inserted arecord into the table with the xml type column. Now I want to parse the data from the xmltype field into a relational table. I have been using the following select statement to accomplish this - and it does work if there is data in all the selected fields but when the filed is null then the whole select statement fails and brings back 'no rows returned'.If the value is null I want the select statment to return null. please give any ideas.
    SELECT version,frmd_transaction_date,extractValue(value(b), 'event_update/location')"location",
    extractValue(value(b), 'event_update/sending_system')"sending_system",
    extractValue(value(b), 'event_update/event_identifier')"event_identifier",
    extractValue(value(b), 'event_update/event_link')"event_link",
    extractValue(value(b), 'event_update/organization_code')"organization_code",
    nvl(extractValue(value(c), '/schedule/event_duration_minutes'),'000')"event_minutes"
    FROM fraamed_user.frmd_event_update , TABLE(xmlsequence(extract(xml_event_update, '/event_update')))b,
    TABLE(xmlsequence(extract(xml_event_update, '/event_update/schedule')))c

    ...then I guess you have to rewrite the query.
    Is schedule another xml sequence inside of event_update sequence ?
    If it is not you can try this :
    SELECT version,frmd_transaction_date,extractValue(value(b), '/event_update/location/text()')"location",
    extractValue(value(b), '/event_update/sending_system/text()')"sending_system",
    extractValue(value(b), '/event_update/event_identifier/text()')"event_identifier",
    extractValue(value(b), '/event_update/event_link/text()')"event_link",
    extractValue(value(b), '/event_update/organization_code/text()')"organization_code",
    extractValue(value(b), '/event_update/schedule/event_duration_minutes/text()')"event_minutes"
    FROM fraamed_user.frmd_event_update , TABLE(xmlsequence(extract(xml_event_update, '/event_update')))b
    ...if yes, did you try nvl function (I don't think this would be a solution of a problem):
    SELECT version,frmd_transaction_date,nvl(extractValue(value(b), '/event_update/location/text()')"location", 'NULL VALUE'),
    nvl(extractValue(value(b), '/event_update/sending_system/text()')"sending_system",'NULL VALUE'),
    nvl(extractValue(value(b), '/event_update/event_identifier/text()')"event_identifier",'NULL VALUE'),
    nvl(extractValue(value(b), '/event_update/event_link/text()')"event_link",'NULL VALUE'),
    nvl(extractValue(value(b), '/event_update/organization_code/text()')"organization_code",'NULL VALUE'),
    nvl(extractValue(value(c), '/schedule/event_duration_minutes/text()')"event_minutes",'NULL VALUE')
    FROM fraamed_user.frmd_event_update , TABLE(xmlsequence(extract(xml_event_update, '/event_update')))b,
    TABLE(xmlsequence(extract(xml_event_update, '/event_update/schedule')))c
    If none of this works post your xml schema.

  • Reading a file and parsing the data for a calculation method

    i am trying to read a file with 3 feilds double double and int . am able to read the file but i am getting an exception right befor i parse the data ...code
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.*;
    //import com.sun.java.util.jar.pack.Package.File;
    public class FileTester {
    public static String mLine;
         public static void main(String[] args) {
              BufferedReader in = null;
              try{
              File f = new File ("loan.txt.txt");
              in = new BufferedReader(new FileReader(f));
              catch(FileNotFoundException e)
                   System.out.println("file does not exist");
                   System.exit(0);
              try{
              String mLine = in.readLine();
              while (mLine != null){
                   System.out.println(mLine);
                   mLine = in.readLine();
              }}catch(Exception e)
              {System.out.println(e.getMessage());
              String []data = mLine.split("\t");
              double loan = Double.parseDouble(data[0]);
              double interest = Double.parseDouble(data[1]);
              int term = Integer.parseInt(data[2]);
              System.out.println(loan+interest+term);
    afterwards i would like to break this up into three methods to feed the values to a calculation class

    Take a look at your while loop. It continues to loop as long as mLine != null. Therefore it stops looping when mLine IS = null. So can you now see why the following line of code would cause problems?
    String []data = mLine.split("\t");How is the data stored in your file? Is it a single line with the three values separated by a tab? If so you can do away with the while loop and just call readLine() once. Otherwise you will have to process each line you read inside the while loop.
    P.S. use the code button when posting code. There is a button above the textfield when use post a reply.

  • How to parse system date to return Date and in yyyy-MM-dd format?

    DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd");
    java.util.Date date = new java.util.Date ();
    String dateStr = dateFormat.format (date);
    try{
    Date date2 = dateFormat.parse (dateStr);
    }catch(ParseException pe){
    pe.printStackTrace();
    Actually, After parsing the date from string, again it is converted into dfault format i.e. 21 Jan 00.00.00 etc...
    But I want this parsing date in yyyy-MM-dd format and again to return date.
    Can anybody tell me how to do this?

    DateFormat dateFormat = new SimpleDateFormat
    ("yyyy-MM-dd");
    java.util.Date date = new java.util.Date ();
    String dateStr = dateFormat.format (date);
    try{
    Date date2 = dateFormat.parse (dateStr);
    }catch(ParseException pe){
    pe.printStackTrace();
    Actually, After parsing the date from string, again
    it is converted into dfault format i.e. 21 Jan
    00.00.00 etc...
    But I want this parsing date in yyyy-MM-dd format and
    again to return date.
    Can anybody tell me how to do this?A Date object does not have a format, it represents a moment in time. You can use SimpleDateFormat to return a String representing that moment in time in many formats - this does not change the Date object to have that format (which it cannot since it does not contain a format).

  • How to parsing xml data in sql statement??

    Hi friends, I have a table which contain column as clob ,stores in xml format, for example my column contain xml data like this
    <Employees xmlns="http://TargetNamespace.com/read_emp">
       <C1>106</C1>
       <C2>Harish</C2>
       <C3>1998-05-12</C3>
       <C4>HR</C4>
       <C5>1600</C5>
       <C6>10</C6>
    </Employees>
      Then how to extract the data in above xml column data using SQL statement...

    Duplicate post
    How to parsing xml data in sql statement??

  • How to parse timestamp data

    Hi,
    I am not able to parse timestamp data. I am bringing this timestamp from AD through LDAP attribute through java code. I want date and time from this timestamp so that I can compare it with another date and time and get the difference between the two.
    If anybody knows the solution for this then please let me know.
    Thanks,
    Kalpana.

    Hi Kalpana,
    try this to convert AD date to java date format
         final long FILETIME_EPOCH_DIFF = 0xa9735dcc400L;
         final long HUNDRED_NANO_PER_MILLI_RATIO = 10000L;
         long activeDirDate = 129476773898586231L;
         long l1 = activeDirDate / 10000L;
         long l2 = l1 - FILETIME_EPOCH_DIFF;
         Date newdate = new Date(l2);
         System.out.println("AD Date is in Java Date format : "+newdate);
    Thanks,
    Pallavi

  • Parse a Date to String

    Hi
    i would use this to parse String to Date :
    public Date parseFromString(String dateString){
          try {
              java.text.SimpleDateFormat formatter
                  = new java.text.SimpleDateFormat("dd/MM/yy");
              return formatter.parse(dateString);
          catch (Exception e) {
          return null;
      }how can i parse a Date to string?
    Thanks
    D

    check the API Docs for SimpleDateFormat - particularly the format method. public StringFormatFromDate(Date date){
          try {
              java.text.SimpleDateFormat formatter
                  = new java.text.SimpleDateFormat("dd/MM/yy");
              return formatter.format(date);
          catch (Exception e) {
               // You really shouldn't catch Exception - and you really should do something in your catch
               // blocks so you don't post a question like "my code executes no problem, but nothing happens...
               e.printStackTrace();
          return null;
      }

  • Parsing a date string

    I need to parse a bunch of date strings in 'UTCG' format (whatever that really means).
    They all look like:
    1 Jan 2001 00:00:00.00
    I can't figure out which of the Java date formats parse this. I've tried many varients of:
    DateFormat.getTimeInstance(DateFormat.MEDIUM,Locale.GERMANY)
    without success.
    Help!!!!

    Here is a bit of info from the API doc - notice in the first paragraph it talks about the Date object, format seems similar. At the bottom of info is the Short, Long, etc, format tyoes, check those out... - Bart
    public abstract class DateFormat
    extends Format
    DateFormat is an abstract class for date/time formatting subclasses which formats and parses dates or time in a language-independent manner. The date/time formatting subclass, such as SimpleDateFormat, allows for formatting (i.e., date -> text), parsing (text -> date), and normalization. The date is represented as a Date object or as the milliseconds since January 1, 1970, 00:00:00 GMT.
    DateFormat provides many class methods for obtaining default date/time formatters based on the default or a given locale and a number of formatting styles. The formatting styles include FULL, LONG, MEDIUM, and SHORT. More detail and examples of using these styles are provided in the method descriptions.
    DateFormat helps you to format and parse dates for any locale. Your code can be completely independent of the locale conventions for months, days of the week, or even the calendar format: lunar vs. solar.
    To format a date for the current Locale, use one of the static factory methods:
    myString = DateFormat.getDateInstance().format(myDate);
    If you are formatting multiple dates, it is more efficient to get the format and use it multiple times so that the system doesn't have to fetch the information about the local language and country conventions multiple times.
    DateFormat df = DateFormat.getDateInstance();
    for (int i = 0; i < a.length; ++i) {
    output.println(df.format(myDate) + "; ");
    To format a date for a different Locale, specify it in the call to getDateInstance().
    DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
    You can use a DateFormat to parse also.
    myDate = df.parse(myString);
    Use getDateInstance to get the normal date format for that country. There are other static factory methods available. Use getTimeInstance to get the time format for that country. Use getDateTimeInstance to get a date and time format. You can pass in different options to these factory methods to control the length of the result; from SHORT to MEDIUM to LONG to FULL. The exact result depends on the locale, but generally:
    SHORT is completely numeric, such as 12.13.52 or 3:30pm
    MEDIUM is longer, such as Jan 12, 1952
    LONG is longer, such as January 12, 1952 or 3:30:32pm
    FULL is pretty completely specified, such as Tuesday, April 12, 1952 AD or 3:30:42pm PST.

  • Parsing a date string without knowing the pattern

    Hi guys.
    Imagine this tool that works with files. At a certain point the tool reads a date from a certain file. The date may come in different flavours (read patterns), depending from file to file, I do not have control over there, so I'm stuck in this moment when I have to parse the date without knowing it's pattern. In one file it's 05-12-2005, in others it's 2007-11-03 12:50:00.
    How do I proceed here?
    Thanks.

    This is going to be a problem.
    The most obvious advice would be to create a list of known patterns and then try each of them with the String in question. One of the downsides of this is that you may get false positives, because for example you interpret a month as a day or vice-versa.
    I think your starting place will be to figure out how many different date formats you actually have. If the answer truly is more than you can count or new ones are created all the time then you are going to have address that somehow because you simply can't have that. There's just no way to deal with a unlimited number of formats.
    If you do get a list of formats then I would try what I first suggested but think of ways in which you can avoid false positives.

  • Parsing Options Data from Files

    With the help of the folks on this discussion board, I now have a directory filled with daily options data for all traded options. What I would like to do now is parse the data out so that I have one file with all the options data for one or two stocks.
    Now I have a file named in the YYYYMMDD.txt format for every trading day. The data in the file looks like this:
    AAF,A,,,,,5.65,0,30.0,6.25,6.5,334,2008
    AAG,A,,,,,1.71,4,35.0,1.7,1.79,2049,2008
    I need to pull information out of that file for specific symbols, and concatenate the date, which can be derived from the file name, at the end of each line.
    So far I have a script that goes through the files and parses the information, but I do not know how to insert the information into a blank document and add the date. Here is what I have so far.
    set fPath to "path:to:directory:"
    tell application "Finder" to set tList to name of every file of folder fPath
    repeat with i in tList
    do shell script "grep ,PGH, " & quoted form of POSIX path of fPath & i
    end repeat
    Thank you in advance.

    Thanks for the quick reply.
    Here is an exert from an example file that I included in my original post. Let me describe the information a little bit, and I think you will see where I am going with grep.
    AAF,A,,,,,5.65,0,30.0,6.25,6.5,334,2008
    AAG,A,,,,,1.71,4,35.0,1.7,1.79,2049,2008
    The first data is the options symbol, and the second is the underlying stock symbol for the option. I have only included two rows but the text files include hundreds of thousands of rows. The first two rows that I am using in my example are for Agilent Technologies whose stock symbol is "A".
    So if I use the UNIX command GREP and do , stock symbol , plus the file I can pull out the options information I am interested in for just one stock. In the case of my original post, I was trying to get information for PGH.
    For example,
    grep ,PGH, /path/to/file/20080102.txt
    returns:
    PGHAC,PGH,,,,,2.7,0,15.0,2.8,3.1,81,2008
    PGHAD,PGH,,,,,0.05,16,20.0,0.0,0.05,5995,2008
    PGHAV,PGH,,,,,5.5,0,12.5,5.2,5.6,0,2008
    PGHAW,PGH,,,,,0.6,96,17.5,0.45,0.7,3659,2008
    PGHAX,PGH,,,,,0.1,0,22.5,0.0,0.05,1476,2008
    PGHBC,PGH,,,,,,0,15.0,2.8,3.1,0,2008
    PGHBD,PGH,,,,,,0,20.0,0.0,0.1,0,2008
    PGHBV,PGH,,,,,,0,12.5,5.3,5.6,0,2008
    PGHBW,PGH,,,,,0.55,0,17.5,0.6,0.75,22,2008
    PGHBX,PGH,,,,,,0,22.5,0.0,0.05,0,2008
    PGHDC,PGH,,,,,2.7,0,15.0,2.8,3.1,376,2008
    PGHDD,PGH,,,,,0.15,8,20.0,0.1,0.15,3048,2008
    PGHDV,PGH,,,,,5.6,0,12.5,5.3,5.6,29,2008
    PGHDW,PGH,,,,,0.95,26,17.5,0.85,1.0,2485,2008
    PGHDX,PGH,,,,,0.15,0,22.5,0.0,0.1,224,2008
    PGHGC,PGH,,,,,2.9,10,15.0,2.8,3.2,133,2008
    PGHGD,PGH,,,,,0.3,16,20.0,0.2,0.3,563,2008
    PGHGV,PGH,,,,,5.6,0,12.5,5.2,5.6,10,2008
    PGHGW,PGH,,,,,1.05,7,17.5,0.95,1.15,1347,2008
    PGHGX,PGH,,,,,,0,22.5,0.0,0.1,0,2008
    PGHMC,PGH,,,,,0.05,0,15.0,0.0,0.05,915,2008
    PGHMD,PGH,,,,,2.1,25,20.0,1.95,2.2,1072,2008
    PGHMV,PGH,,,,,0.03,0,12.5,0.0,0.05,30,2008
    PGHMW,PGH,,,,,0.1,5,17.5,0.1,0.25,4430,2008
    PGHMX,PGH,,,,,4.6,0,22.5,4.4,4.8,164,2008
    PGHNC,PGH,,,,,0.1,0,15.0,0.05,0.1,30,2008
    PGHND,PGH,,,,,2.55,0,20.0,2.15,2.4,35,2008
    PGHNV,PGH,,,,,,0,12.5,0.0,0.05,0,2008
    PGHNW,PGH,,,,,0.4,5,17.5,0.35,0.5,38,2008
    PGHNX,PGH,,,,,,0,22.5,4.6,5.0,0,2008
    PGHPC,PGH,,,,,0.2,10,15.0,0.15,0.25,431,2008
    PGHPD,PGH,,,,,2.6,35,20.0,2.55,2.8,326,2008
    PGHPV,PGH,,,,,0.1,0,12.5,0.0,0.1,115,2008
    PGHPW,PGH,,,,,0.85,0,17.5,0.75,0.9,1431,2008
    PGHPX,PGH,,,,,4.5,0,22.5,4.9,5.2,91,2008
    PGHSC,PGH,,,,,0.5,0,15.0,0.35,0.5,57,2008
    PGHSD,PGH,,,,,3.3,0,20.0,3.0,3.4,527,2008
    PGHSV,PGH,,,,,0.15,30,12.5,0.05,0.15,0,2008
    PGHSW,PGH,,,,,1.45,1,17.5,1.3,1.45,664,2008
    PGHSX,PGH,,,,,5.3,0,22.5,5.3,5.7,117,2008
    Which is the options data for one stock on one day. But I want the options data for one stock for everyday. I hope this makes sense.

  • How to parse URL Data into an NSString Array in iphone application

    Hi Every one
    I am newbie to iphone programming. I am having problem with reading and displaying the data into the table view. My application has to be designed like this. There is a csv file in the server machine and I have to access that URL line by line. Each line consists of 8 comma separated values. Consider each line has first name, second name and so on. I have to parse the data with comma and a newline and store them in an array of first name, second name array an so on. The next thing is I have to set first name second name combined and must be displayed in the UITableView. Can anyone provide me with an example of how to do it? I know I am asking the solution but I encountered a problem in connection methods separately and parsing simultaneously. You help is much appreciated.
    Thanks

    What does that have to do with a URL?
    The only thing that doesn't sound good is "array of first name" and "second name array". For each row, extract all the field and store them in an NSDictionary. Add a derived field consisting of first name concatenated with last name. That will be easy to display in a table.

Maybe you are looking for

  • Viewing stereo tracks in arrange window?

    Hello. I created an interleaved stereo audio file. But the track looks graphically like it's mono in the arrange window. Is there a way to have a graphical representation that it is a stereo file (like in Live, Pro Tools, Studio Vision, etc...)? (If

  • Random Kernel Errors and need to repair disk

    After trying to partition for Bootcamp, the computer locked into a Kernel error. I went to validate the disk and discovered that I need to repair the disk. I have tried booting from my OSX installation disk to access the repair disk functionality. I

  • Can't manually add editable regions to head in template

    When I created my main template in Dreamweaver CS6 for my website, I had copied most of the page code from another layout I already had, including the head code.  I did not realize there were already editable regions built into the head section of th

  • How to update and save values changes during run time

    I have string and numeric controls on my front panel that the operator can change the values of and was wondering if there was any way to save these changes everytime the vi was closed so they would stay current??? thanks dale walker [email protected

  • Is it possible to play a quick time player video on a macbook air? I've installed Mavericks on my computer already

    I'm trying to watch a video on my MacBook air trought quick time player but the video just won't open.  Every time I try to open it it says: "QuickTime Player can't open "IMG_1916.MOV". To see if additional software is available that will enable quic