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.

Similar Messages

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

  • Is it possible to delete extended properties without knowing the id?

    Hello,
    Can you delete any custom extended properties without knowing their ID?
    I took over managing a feature that used EWS to send emails to customers.The current code creates a new GUID, and thus new Extended Property, every time an email is sent.
    // Create a custom extended property and add it to the message.
    var myExtendedPropertyDefinition = new ExtendedPropertyDefinition(Guid.NewGuid(), "MyGuidId", MapiPropertyType.String);
    mail.SetExtendedProperty(myExtendedPropertyDefinition, "MyGuidId");
    // Send and save a copy
    mail.SendAndSaveCopy();
    Is there a way to delete any of the custom extended propeties without knowing the IDs?
    Thank you

    No you can't do that in EWS you need to know the details of the property you want to Read/Write or delete. EWS has no method of enumerating all extended properties either you would need to use MAPI to do this.
    >>The current code creates a new GUID, and thus new Extended Property, every time an email is sent.
     I'd question the design of this what where they trying to acheive ? Why not have ths same property with a different Value ? else using an X-header would be better idea at least then it will persist ouside of your Exchange infrastructure and even
    inside would be more discoverable.
    Cheers
    Glen

  • Loading a class via reflection without knowing the full qualified path ?

    Hi there
    I d like to load a class via reflection and call the constructor of the class object. My problem is that I dont know the full qulified name e.g. org.xyz.Classname bur only the Classname.
    I tried different things but none seem to work:
         1. Class c = Class.forName("Classname");  //does not suffice, full qualified name required
    2. ClassLoader classloader = java.lang.ClassLoader.getSystemClassLoader();
             try {
               Class cl = classloader.loadClass(stripFileType(Filename));//if i do not pass the full qualified name i get a ClassNotFoundException
    3. I tried to consruct a class object with my own classloader , calling:
              Class cl = super.defineClass(null, b, 0, b.length );     b is of type byte[]This almost works. I get a class Object without knowing the full qulified path. I can transform a filename into a raw array of bytes and I get the class out of it. But there is still a problem: If there are more than on classes defined in the same textfile I get an InvocationTargetException.
    It looks like this:
    package org.eml.adaptiveUI.demo;
    import com.borland.jbcl.layout.*;
    import java.awt.*;
    import org.eml.adaptiveUI.layout.*;
    import javax.swing.*;
    import java.awt.event.*;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2003</p>
    * <p>Company: </p>
    * @author not attributable
    * @version 1.0
    public class twoButtons extends JFrame {
      SPanel sPanel1 = new SPanel();
      JButton jButton1 = new JButton();
      GridBagLayout gridBagLayout1 = new GridBagLayout();
      GridBagLayout gridBagLayout2 = new GridBagLayout();
      public twoButtons() throws HeadlessException {
        try {
          jbInit();
        catch(Exception e) {
          e.printStackTrace();
      public static void main(String args[]){
        twoButtons twob = new twoButtons();
        twob.pack();
        twob.show();
      private void jbInit() throws Exception {
        this.getContentPane().setLayout(gridBagLayout1);
        jButton1.setText("button 1");
        jButton1.addActionListener(new TransformationDemo_jButton1_actionAdapter(this));
        this.getContentPane().add(sPanel1,  new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
                ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(57, 52, 94, 108), 35, 44));
        sPanel1.add(jButton1,  new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 41, 0, 0), 0, 0));
      void jButton1_actionPerformed(ActionEvent e) {
        System.out.println("button 1 source: " + e.getSource());
        System.out.println("d: " + e.getID());
       System.out.println("/n commmand: " + e.getActionCommand());
    class TransformationDemo_jButton1_actionAdapter implements java.awt.event.ActionListener {
      twoButtons adaptee;
      TransformationDemo_jButton1_actionAdapter(twoButtons adaptee) {
        this.adaptee = adaptee;
      public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }As you can see there is the class TransformationDemo_jButton1_actionAdapter class defined in the same classfile. The problem is now that the twoButtons constructor calls the TransfomationDemo_jButton1_actionAdapter constructor and this leads to InvocationTargetException. I dont know if this is a java bug because it should be possible.
    Can you help me?

    hi thanks at first,
    the thing you mentioned could be a problem, but I dont think it is.
    If I have the full qualified name (which I havent) then everything goes normal. I only have to load the "twoButtons" class and not the other (actionadapter class), so I dont think this is the point. In this case the twoButtons constructor constructs an object of the actionadapter class and everything goes well. The bad thing is though that I do not have the full qulified name :(
    Invocation target exception tells me (in own words): Tried to acces the constructor of the actionadapter class (which is not public) out of class reflectionTest class .
    reflectionTest is the class where the reflection stuff happens and the twoButttons class is defineClass() ed.
    The problem is, only twoButtons class has the rights to call methods from the actionadapter class, the reflection class does not. BUT: I do not call the actionadapter methods from the reflection class. I call them only from the twoButtons class.
    I hope somebody understands my problem :)

  • How do you reset an ipad mini without knowing the password?

    I have just recently changed my password, but know i have forgot the new one. How do you reset the ipad without knowing the password?

    If you mean the passcode to unlock the iPad then you will need to connect it to the computer that you normally sync to and you should then be able to reset the iPad and restore/re-sync your content to it (http://support.apple.com/kb/HT1212) - you may need to put the iPad into recovery mode in order to be able to reset it : http://support.apple.com/kb/ht1808
    If you do it via a different computer then :
    If you restore on a different computer that was never synced with the device, you will be able to unlock the device for use and remove the passcode, but your data will not be present.

  • Parse Localized Date String

    The javascript function util.printd has great support for localized date strings using XFAPicture.  However, util.scand doesn't appear to have the same support.  How would I go about parsing a date string that is in a localized form?
    Thanks in advance.

    Do you have your application language preference set for Spanish for Acrobat/Reader?
    Printing is done form the Date Object and not a string value.

  • How do I change the password in iPhone without knowing the current PW?

    I synced my iPhone 4S and know my access password very well, yet the phone tells me it's wrong. I have no access to my data and can't make phone calls as the access is denied.
    How can I retrieve control over my phone again? Is there a way to change the pw without knowing the current one?
       ---- HELP!!!

    LOST PASSCODE
    You may be able to reset the passcode by restoring the device.
    Connect the device to the computer with which you normally sync and open iTunes.
    Note: If iTunes prompts you to enter the passcode, try another computer that you have synced with. Otherwise, go to "If you have never synced your device with iTunes", below.
    Right-click the device in the left column and select Back up.
    When the backup is complete, select Restore.
    When finished, restore from your most recent backup.
    Otherwise read this
    If that doesn’t work  you will need to perform a factory restore to remove it. Or read:
    Enter Wrong passcode
    http://support.apple.com/kb/ht1212

  • But how do I create a new iTunes backup password without knowing the previous one?

    In case anyone keeps track of such things, I'm among those folks who really doesn't recall ever being asked to create an iTunes backup password, but that's irrelevant to my question.
    I'm not in any bind. I don't need my backup files to restore anything. I will shed no tears as they are moved to the Recycle Bin (indeed, I will gladly do the deed myself).
    That said, it appears impossible to create a new backup password without knowing the previous one.
    If the only "solution" is to wipe my iPhone's memory and start from scratch, I will be a sad camper.
    Any help? Are backups to iCloud encrypted?
    Cheers...

    Additionally:
    Be super critical & meticulous (and whatever other synonym I missed) when you get a new password:
    Write it onto your bedroom wall, or someplace off of a computer that you will always find.
    If you active 2-step verification, the key is VERY important. Lose it & you may be toast.
    If you don’t 2 step verify, & use the Security Question instead --> do not lose, or forget the answers.
    Very nearly the same outcome!!!!!:  Bad experience.
    If you add a 2nd email address, make sure its a RESCUE address not just an alternate address.
    If you lose these, you lose access to your 3rd party purchases via Appstore for future upgrade. That will make you VEWY, VEWY UNHAPPY. Apple new OS versions do update, but add a new device & likely you will be unable to use your content on that device. It will never load if the ID locks up.

  • I forgot my password for my apple ID. Any ideas on how to put in a new one without knowing the old one?

    I forgot my password for my Apple ID. Anyone have a solution on how to put in a new one without knowing the old one?
    Thanks

    Welcome to Apple Support Communities
    You have to reset your password. You can do this in this site > http://iforgot.apple.com

  • How can I reset my administrator password, without knowing the original administrator password?

    Hi guys,
    I use a MacBook Pro with OS X 10.8 Mountain Lion. A few months ago I reset my administrator password and have not been able to remember it since. Consequently, I haven’t been able to do any software updates, my computer is running slow and I'm getting a lot of pop-up junk on my screen. I’m the only user on my computer, apart from the Guest User (Sharing only).
    How can I reset my administrator password, without knowing the original password?
    Thanks.

    Resetting Password and/or Home Folder Permissions

  • How do i reset an admin password without knowing the original?

    How can i reset my admin password on my macbook pro without knowing the original password?

    Insert a compatible Mac OS X DVD, restart with the Option key held down, and use its Reset Password utility. If the computer has a firmware password set, you need to know that.
    (58431)

  • HT4113 how to unlock an ipod touch without knowing the password

    how to unlock an ipod touch without knowing the password

    Connect the iPod to your computer and restore via iTunes. Place the iPod in Recovery mode if necessary to allow the restore.

  • HT4865 How to delete the preowner icloud account without knowing the password?

    How to delete icloud account from pre owner without knowing the password?

    II'm in the same situation. Purchased a refurbished IPhone 5. I had to do a factory reset and when I reset it again, itunes tells me that the phone is linked to someone else. Called the company I bought the phone from and they say iTunes can do a master reset to link my iTunes account to the phone. Have any of you heard of this being possible?

  • How do you unlock an ipod touch without knowing the password

    How do you unlock a ipod touch 4th generation without knowing the password?

    Connect the iOS device to your computer and restore via iTunes. Place the iOS device in Recovery Mode if necessary to allow the restore.
    If recovery mode does not work try DFU mode.
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    For how to restore:
    iTunes: Restoring iOS software
    To restore from backup see:
    iOS: How to back up
    If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
    You can redownload iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • Can we send a request without knowing the actual url..

    Tomcat is running at the back.
    I know the port no on which the server is running now.
    Can we send a request to the server even if we dont know the exact url
    for example I developed a form which authenticates the user, after authenticating the url will be some thing like this
    http://localhost:8090/temp/AdminRegister?uname=user?pass=user123now can the user login even without knowing the exact username and password by manipulating the url..

    it is your own risk to your applets to communicate with DBs because nobody suggests that. I agree with the Javascript story and the frames. It can be done but i thought he wanted to do that in one single page. And finally, i dont trust frames that much. I have seen many times the 404 error found on pages and because i use dynamic pages i have to make connection for each frame. and with throusands users being online it is bad for my server (traffic).

Maybe you are looking for

  • Printing only single page -SAPSCRIPT

    Hi, I am printing checks and in the page attributes NEXT Page is EMPTY. still it is printing scedond page which I don't need. Any ideas? rgds Praveen

  • AP Trial Balance/Supplier Name

    Hi Experts, When I selected an inactive supplier for AP Trial Balance , I got a messte: Value XXX in segment Supplier Name has expired. I checked the value set :AP_SRS_VENDOR_NAME , there is no condition for active supplier, why can't I select an ina

  • Problem changing sld data supplier slddsuser to new userid in VA

    We are experiencing lockouts with slddsuser in the SLD so I planned to change all fo the userid's under sld data suppliers to a unique userid for each client.  I created a copy of user slddsuser in solution manager and made sure in the UME the new us

  • Separating images within a photo

    I have many birding photos with several birds in one image, such as 3 terns flying.  I want to be able to move one bird closer to another bird. Is that possible?

  • Still can't install CS4 Design Premium on Windows 8.1

    Did what you said. I uninstalled, used your cleaner tool and reinstalled. Still have the same problem. Would be nice if I could actually get some real help.