Parsing date format

Hi there.
I had a brief foray some while ago into Java, got frustrated, put it aside.
Well now I've started again with a problem.
If I were to want to parse only sentences of "dd-mm-yyyy" (date format) would (or is it should?) I use if/else type statements? I don't want to specify that we can't have the 99th day of the 99th month or anything like that but I'd like to make sure that it accepts only the format ..2 numerals hyphen 2 numerals hyphen 4 numerals.
Or should I be researching the tokeniser? From what I've seen it's not used with if/else.
From reading this you could probably guess I haven't got much idea.
A pointer in the right direction would be appreciated.

OK
Hmm'
Input from keyboard,
recognise input,
give back to the output if in correct format
or give an error.
I found some explanation to SimpleDateFormat although I don't yet know how to apply it :-(
Well, I only asked for a pointer didn't I :-)
Thanks anyway.

Similar Messages

  • Error while parsing date format

    Hi Friends
    I am using db2 as backend for my project and currently facing an issue with the parsing of the date.
    The date being returned from the db is in the format - yyyy-MM-dd-HH.mm.ss.SSS000 and the return type is String.
    when i try to parse and convert it into a date object. i get the following error
    java.text.ParseException: Unparseable date: "2011-05-30-20.23.25.319000"
    the code to format is as below
    String dateTime = "2011-05-30-20.23.25.319000";
    java.text.SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSS000");
    Date date =format.parse(dateTime);
    please provide your comments as to what i am doing wrong here.and if possible let me know the solution.
    Best Regards
    Vikeng

    Use this instead:
    java.text.SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSS");

  • 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

  • Parsing Issue in Filter For Date Format

    Hi Folks,
    I am having Parsing Issue on "Key Date" Object in Universe. See the Error and Code below for your review
    Error: Parse Failed: Exception: DBD, The value entered is not valid. It must adhere to one of the following formats.
    YYYYMMDD
    DD.MM.YYYYState:N/A
    Code:
    <OPERATOR VALUE="AND"><OPTIONAL><FILTER KEY="0I_DAYIN"><CONDITION OPERATORCONDITION="Between"><CONSTANT TECH_NAME="@Prompt('Day Interval From','A','Calendar Day\LovDay IntervalBase',mono,primary_key)"/><CONSTANT TECH_NAME="@Prompt('Day Interval To','A','Calendar Day\LovDay IntervalBase',mono,primary_key)"/></CONDITION></FILTER></OPTIONAL><FILTER KEY="0P_KEYDA"><CONDITION OPERATORCONDITION="Equal"><CONSTANT TECH_NAME="@Prompt('Key Date','D',,mono,free)"/></CONDITION></FILTER></OPERATOR>
    This universe is created by someone else and client need to modify it with a calendar but i did not modify it yet however its already giving me the hard time. Kindly advise, any kind of help will be appreciated
    Thanks

    Hi,
    With the information provided I cannot for sure get to the error but here is what I would check.
    Firstly, I was wondering if the 5th parameter in the @Prompt can be Primary_Key. I thought it would be either free or constrained.
    Secondly, please the LOV values for the @ prompt are being populated from 'Calendar Day\LovDay IntervalBase'. So I would check the date format being used there.
    Third, the To and From dates are alphaneumeric and not dates, so I am not sure how the comparision would happen.
    Hope this helps.
    Regards,
    Madhur

  • 01.01.0000 date parse and format

    Could somebody explain is wrong here?
    SimpleDateFormat frm = new SimpleDateFormat("yyyyMMddHHmmss");  // formatter
    frm.setTimeZone(TimeZone.getTimeZone("UTC"));   // UTC time zone
    // --- No problem for the next code ---
    String inDate = "19700101000000";  // 01.01.1970 input date
    long stamp;
    try {
        stamp = frm.parse(inDate).getTime();   // input date in long
    } catch (ParseException ex) {
        System.out.println("Interruption");
        stamp = 0;
    String outDate = frm.format(stamp);  // output date
    System.out.println("inDate=>" + inDate + "_longDate=>" + stamp + "_outDate=>" + outDate);
    // --- No idea why next code is working wrongly ---
    inDate = "00000101000000";  // 01.01.0000 input date
    try {
        stamp = frm.parse(inDate).getTime();   // input date in long
    } catch (ParseException ex) {
        System.out.println("Interruption");
        stamp = 0;
    outDate = frm.format(stamp);  // output date
    System.out.println("inDate=>" + inDate + "_longDate=>" + stamp + "_outDate=>" + outDate);I try to parse and format the time stamp 01.01.0000 00:00:00. On the finish I have 01.01.0001 instead of the correct 01.01.0000
    inDate=>19700101000000_longDate=>0_outDate=>19700101000000
    inDate=>00000101000000_longDate=>-62167392000000_outDate=>00010101000000

    You are calling format with a long parameter. The only format that matches that signature that I can see would be Format.format(Object) assuming autoboxing is changing the long to a Long.
    Format.format(Object) eventually calls DateFormat.format(Object, StringBuffer, FieldPosition). I have never used this method so I am not sure what it does.
    Was your intention to actually call this method?
    See the following example:
    System.out.println("Test 1: " + frm.format(new Long(0l), new StringBuffer(), new FieldPosition(0)));  
    System.out.println("Test 2: " + frm.format(new Long(-62167392000000l), new StringBuffer(), new FieldPosition(0)));  
    Test 1: 19700101000000
    Test 2: 00010101000000Edited by: jbish on Apr 26, 2013 12:43 PM
    Edited by: jbish on Apr 26, 2013 1:09 PM

  • How to parse date in yyyyMMddHH'.'mmss'00' format

    Hi all,
    In an applet I am creating, I receive a timestamp in the following format:
    yyyyMMddHH'.'mmss'00'
    As an example, the date string I receive is "2003011419.304600" which, when decoded, gives, Jan 14 19:30:46 2003.
    I need to convert this to the MM/dd/yyyy format for date and HH:mm:ss:SS for time, in order to display it in my applet.
    Here is the scheme I am using:
    String inputDateFormat = "yyyyMMddHH'.'mmss'00'";
    SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy");
    SimpleDateFormat timeFormatter = new SimpleDateFormat ( "HH:mm:ss:SS");
    SimpleDateFormat formatter = new SimpleDateFormat ( inputDateFormat );
    // Assume the tokens vector contains the correct string
    Date dateTime = formatter.parse ( ( String ) tokens.elementAt ( 0 ) );
    String date = dateFormatter.format ( dateTime );
    String time = timeFormatter.format ( dateTime );
    However, I am getting parse exception, Unparseable date error at the following line:
    Date dateTime = formatter.parse ( ( String ) tokens.elementAt ( 0 ) );
    Is this because the date format does not contain any delimiters (like space or period or slash)? I am kinda confused.
    Thanks,
    Alan

    What I am wondering is
    whether the date can be successfully parsed even if it
    is in the strange format as above.My guess at this point in time is that this is a bug. I did not find anything in the bug database that suggested that it is known.
    The following code demonstrates it.
    Please post it (or let me know so I can post it.)
    I am using build 1.4.0-b92, so if someone could try it on 1.4.1 it would be nice.
         String s;
         SimpleDateFormat f;
         java.util.Date d;
         // Works
         s = "2003011419.3046";
         f = new SimpleDateFormat("yyyyMMddHH.mmss");
         d = f.parse(s);
         System.out.println("date with no specials=" + d);
         // Works with 'a' at end
         s = "2003011419.3046a";
         f = new SimpleDateFormat("yyyyMMddHH.mmss'a'");
         d = f.parse(s);
         System.out.println("date with a at the end=" + d);
         // Works with '>' at end
         s = "2003011419.3046>";
         f = new SimpleDateFormat("yyyyMMddHH.mmss'>'");
         d = f.parse(s);
         System.out.println("date with > at the end=" + d);
         // Doesn't work with '0'(zero) at end
         s = "2003011419.30460";
         f = new SimpleDateFormat("yyyyMMddHH.mmss'0'");
         d = f.parse(s);
         System.out.println("date with digit at end at the end=" + d);

  • Need to parse Japanese Full Date Format

    Hi,
    Locale japanLocale = Locale.JAPAN;
    SimpleDateFormat fullDateFormat = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, japanLocale);
    String dateValue = 2010'?'09'?'12'?' 1'?'15'?'45'?'GMT // Here Japanese character will come instead of ?
    DateFormat initialDateFormat = new SimpleDateFormat(fullPattern, japanLocale);
    Date date = initialDateFormat.parse(dateValue);
    String formattedDate = fullDateFormat.format(date);
    This throws Exception java.text.ParseException: Unparseable date: "2010'?'09'?'12'?' 1'?'15'
    ?'45'?'GMT"
    If you send some good suggestions, it will be appreciable.
    Thanks in Advance
    Suresh

    Japanese full pattern is:
    "yyyy'&#24180;'M'&#26376;'d'&#26085;' (EEEE)
    H'&#26178;'mm'&#20998;'ss'&#31186;' z"
    I need to parse this string.
    OK:
    String pattern = "yyyy'&#24180;'M'&#26376;'d'&#26085;' (EEEE) H'&#26178;'mm'&#20998;'ss'&#31186;' z";
    String date = "2004&#24180;8&#26376;12&#26085; (&#26408;&#26332;&#26085;) 13&#26178;56&#20998;01&#31186; EEST";
    SimpleDateFormat parser = new SimpleDateFormat(pattern, Locale.JAPAN);
    Date d = parser.parse(date);
    System.out.println(d); // prints Thu Aug 12 13:56:01 EEST 2004
    Note that for the sake of portability the two first lines should be written asString pattern = "yyyy'\u5e74'M'\u6708'd'\u65e5' (EEEE) H'\u6642'mm'\u5206'ss'\u79d2' z";
    String date = "2004\u5e748\u670812\u65e5 (\u6728\u66dc\u65e5) 13\u664256\u520601\u79d2 EEST";This is to make it possible to compile your code on a platform that doesn't support Japanese script.
    Can i have your Yahoo / AOL ID?What makes you think I have one? :)

  • OIM date format parsing error on reconciliation

    Hi All,
    I am using OIM 9.0.3 . When I do the recon , I am able to retrieve user from source and created in OIM ,but one of my field is DATE and which I have map to start date.
    Recon Manager shows me that my date field having parsing error. I tried various date format ,but still the error is coming.
    I don't know which format OIM expecting for date type data for I am missing something. Please tell me .
    Thanks in Advance.

    Hi All,
    I created a GTC connector with following configuration
    Staging Directory (Parent identity data): /home/GTC
    Archiving Directory: /home/GTC/archive
    File Prefix: PLC
    Specified Delimiter: |
    File Encoding UTF8
    Source Date Format yyyy/MM/dd hh:mm:ss z
    Reconcile Deletion of Multivalued Attribute Data check box cleared
    Reconciliation Type Full
    In the Configuration Mapping, I created a Status varaible and mapped it to OIM Object Status and changed the Data type of Last Logon TimeStamp to Date.
    The Layout of flat file PLC.csv.txt is like this:
    Account Name|Full Name|Domain|Last Logon Timestamp|Description|GUID|Mail|Employee ID|First Name|Last Name
    PLC\!alders|Steve Alder|PLC.COM|2007/01/10 11:16:27|Directory and Messaging Services|E109B9F8-40BD-4E72-B336-B46600A5B38E|||Steve|Alder
    PLC\!lewisj|Jonathan Lewis|PLC.COM||Data Centre Scheduled Activities Team|1D580887-EDEB-4C87-A079-837AFBAA782F|||Jonathan|Lewis
    I am facing same kind of issues in which I am getting following error on flat file reconciliation;
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,inside getProvider......2
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,validationProviderclassname:com.thortech.xl.gc.impl.validation.IsFloatValidatorProvider, name:IsFloat
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,nameIsFloat
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,inside getProvider......2
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,validationProviderclassname:com.thortech.xl.gc.impl.validation.IsDoubleValidatorProvider, name:IsDouble
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,nameIsDouble
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,inside getProvider......2
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,validationProviderclassname:com.thortech.xl.gc.impl.validation.IsInRangeValidatorProvider, name:IsInRange
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,nameIsInRange
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,inside getProvider......2
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,validationProviderclassname:com.thortech.xl.gc.impl.validation.MatchRegexpValidatorProvider, name:MatchRegularExpression
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,nameMatchRegularExpression
    DEBUG,24 Aug 2009 19:49:38,211,http://XELLERATE.GC.PROVIDERREGISTRATION,inside getProvider......2
    DEBUG,24 Aug 2009 19:49:38,212,http://XELLERATE.GC.PROVIDERREGISTRATION,validationProviderclassname:com.thortech.xl.gc.impl.validation.ValidateDateFormat, name:ValidateDateFormat
    DEBUG,24 Aug 2009 19:49:38,212,http://XELLERATE.GC.PROVIDERREGISTRATION,nameValidateDateFormat
    DEBUG,24 Aug 2009 19:49:38,212,http://XELLERATE.GC.PROVIDERREGISTRATION,come in validationName.equalsIgnoreCase(name)
    DEBUG,24 Aug 2009 19:49:38,212,http://XELLERATE.GC.PROVIDERREGISTRATION,inside getProviderClassName. ..found transformation provider.....
    DEBUG,24 Aug 2009 19:49:38,212,http://XELLERATE.GC.PROVIDERREGISTRATION,inside getProviderClassName....provider class name = ..com.thortech.xl.gc.impl.validation.ValidateDateFormat
    DEBUG,24 Aug 2009 19:49:38,212,http://XELLERATE.GC.PROVIDERREGISTRATION, provider nameValidateDateFormat
    DEBUG,24 Aug 2009 19:49:38,212,http://XELLERATE.GC.PROVIDERREGISTRATION, provider def attribnull
    DEBUG,24 Aug 2009 19:49:38,212,http://XELLERATE.GC.PROVIDERREGISTRATION, provider resp codes{}
    DEBUG,24 Aug 2009 19:49:38,212,http://XELLERATE.GC.PROVIDERREGISTRATION,inside getProviderClassName. ..found transformation provider.....com.thortech.xl.gc.impl.validation.ValidateDateFormat
    DEBUG,24 Aug 2009 19:49:38,212,http://XELLERATE.ADAPTERS,Class/Method: tcADPClassLoader/getClassLoader entered.
    DEBUG,24 Aug 2009 19:49:38,212,http://XELLERATE.ADAPTERS,Class/Method: tcADPClassLoader/getClassLoader left.
    DEBUG,24 Aug 2009 19:49:38,212,http://XELLERATE.GC.PROVIDERREGISTRATION,Loading Provider Class -->com.thortech.xl.gc.impl.validation.ValidateDateFormat WARN,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.FRAMEWORKRECONCILIATION,Record failed on Validation and therefore would not be Reconciled*
    +WARN,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.FRAMEWORKRECONCILIATION,Parent Data -->{Description=2029/03/07 09:01:11, Account Name=HRL\PUNEET, First Name=, Last Logon Timestamp=HRL1.CORP, Domain=Les, GUID=Hrl, Employee [email protected], Full Name=PUNEETKING, Mail=C7F1A30E-A0C7-444E-BA09-EC66E63831EB, Last Name=PUNEET}DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.SCHEDULER.TASK,Class/Method: SchedulerBaseTask/isStopped entered.+*
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.SCHEDULER.TASK,Class/Method: SchedulerBaseTask/isStopped left.
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,Class/Method: SharedDriveReconTransportProvider/getNextPage entered.
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,Class/Method: SharedDriveReconTransportProvider/getNextPage - Data: page size--> - Value: -1
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,pagesize-->-1
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,Class/Method: SharedDriveReconTransportProvider/end entered.
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,Class/Medthod: SharedDriveReconTransportProvider/end - Before calling: copyFilesToArchive(for Parent files)
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,Class/Method: SharedDriveReconTransportProvider/copyFilesToArchive entered.
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,Class/Method: SharedDriveReconTransportProvider/copyFilesToArchive - Data: src File--> - Value: LINUXRECON.COM.txt~
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,src File-->LINUXRECON.COM.txt~
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,Class/Method: SharedDriveReconTransportProvider/copyFilesToArchive - Data: stage Dir--> - Value: /home/GTC
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,stageDir-->/home/GTC
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,Class/Method: SharedDriveReconTransportProvider/copyFilesToArchive - Data: archive Dir--> - Value: /home/GTC/archive
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,archiveDir-->/home/GTC/archive
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,fis closed for /home/GTC/LINUXRECON.COM.txt~
    DEBUG,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,fos closed for /home/GTC/archive/LINUXRECON.COM.txt~
    INFO,24 Aug 2009 19:32:54,225,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,Info Data: file deleted --> - Value: true
    WARN,24 Aug 2009 19:32:54,226,http://XELLERATE.GC.PROVIDER.RECONCILIATIONTRANSPORT,FILE SUCCESSFULLY ARCHIVED : /home/GTC/LINUXRECON.COM.txt~
    I know the issue is with date format but I am not able to solve it after trying so many times with all kind of date formats.
    Kindly help.
    Thanks

  • How can I parse this date format?

    Hey,
    i am trying to write an interface between two applications. One application gives me the following date:
         Wed Jul 16 12:18:20 CEST 2003
    but I need it to look like this:
         16.07.03 12.18:20
    I tryed to use Date and DateFormat to parse and change it but the Date was unparseable.
    I hope somebody can point me to the right direction or show me how I can do the formating.
    Thanx a lot!
    Martin

    If this isn't a well-known date format, I can't see any solution but to write small function yourself which doe the job.
    you can start with :
    String source = "Wed Jul 16 12:18:20 CEST 2003";
    String[] elements = source.split();//splits source around spaces
    then you write functions that map day of week with numbers
    "Mon" --> 1
    "Tue" --> 2
    etc...
    it won't take you days to write this.
    Sometimes it's faster to write the stuff yourself than spending days looking for something pre-defined that may or may not exist.

  • URGENT: XML-SQL: Error parsing different date formats in the same XML file.

    Hi Everyone,
    I have a big problem while using the XML-SQL utility. I have a XML file with different date formats. I get exception like the one below.
    "oracle.xml.sql.OracleXMLSQLException: 'java.text.ParseException: Unparseable date:"
    And the XML file is :
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Info Key="ID">
         <Insert>
              <ID>1</ID>
              <BookingDate>10.12.2001</BookingDate>
              <OpeningTime>19:16</OpeningTime>
         </Insert>
    </Info>
    I have tried using different setDateFormat which is contrary.
    sav.setDateFormat("d.M.y");
    sav.setDateFormat("H:m:s");
    Can someone help me on the same.
    Thanks in advance.
    Subramanian.

    You might have to describe the columns as varchar then modify the table to the right format.

  • Problem with date format dd/mm/yyyy. But I need to convert yyyy-mm-dd.

    Dear friends,
    I have the problem with date format. I receiving the date with the format dd/mm/yyyy. But I can upload to MySQL only in the format of yyyy-mm-dd.
    how should I handle this situation, for this I've created these code lines.But I have some problem with these line. please help me to solve this problem.
    String pattern = "yyyy-mm-dd";
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    try {
    Date date = format.parse("2006-02-12");
    System.out.println(date);
    } catch (ParseException e) {
    e.printStackTrace();
    System.out.println(format.format(new Date()));
    this out put gives me Tue Apr 03 00:00:00 IST 2007
    But I need the date format in yyyy-mm-dd.
    regards,
    maza
    thanks in advance.

    Thanks Dear BalusC,
    I tried with this,
    rs.getString("DATA_SCAD1")// where the source from .xls files
    String pattern = "yyyy-MM-dd";
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    try {
    Date date = format.parse("DATA_SCAD1");
    System.out.println(date);
    } catch (ParseException e) {
    e.printStackTrace();
    System.out.println(format.format(new Date()));
    this out put gives me Tue Apr 03 00:00:00 IST 2007
    But I want to display the date format in yyyy-mm-dd.
    regards,
    maza

  • Parsing data from Serial Port one byte at a time

    Hi everyone,
            What I want to do is read in from the serial port byte by byte and parse each byte that I am reading in. The size of the data read in varies. How do I do that? I can do using .dll but I want to learn how to do it in labview. I searched through the forum for something similar but no luck. I have seen some that puts the VISA read in a while loop and others that puts the property node,  "bytes at Port" in a while loop. What is the difference in doing either way? I am using Labview 7.1 Can anyone point me in the right direction?
    Thanks

    Hi guys..
    I'm still a beginner in using labview tcp/ip function. for now, i have a project to read the labview data with java programming language so that i can monitor that data using any devices that using java, such as PC or cell phone. my task for now is to determine the format of data that being sent (its type, length, etc), coz as far as i done until now, the data that read in the java is still a raw material so that i dont know how to gain the information from that data.
    my question is :
    - how does the type cast work in changing the data format from one to another?
    - how does the bytes to read in tcp read work? coz when i'm changing the length of bytes to read constant from 4 bytes to another, the data is becoming mess up. As far as i know, the bytes to read only read the first "constant number" byte in the tcp read to determine the length and type of the data..
    thanks

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

  • Date formats for SQL statements used by recordset object

    Hi,
    Date formatting appears to be quite problematic for Business One.  I did a forum search for date issues and I don't think I saw any of them with an "answered" status.  I have an issue with formatting a date for the creation of an SQL statement that the DI sends to SQL Server 2005.  I need to format a date so that the localization parameters don't matter for either the client machine or SQL Server's machine.  We don't have a problem as long as our machines are localized as USA.
    I have PL 22 and I have a form - ours - where I use the Today() function to fill a date field.  So this is a date that is not entered by the user.  The result of this function is consistent with the localization parameters on my machine.  We have two other date fields on the form where the user must type in the date. 
    As a test, I changed my machine to the UK parameters.  I then set up the language parameters of Business One for English(United Kingdom).  I changed the date format specifications in Business One so that its format is dd/mm/yy.  I then brought up the form and the field that is formatted by the above function arrived in the form's field as dd/mm/yy.  I then typed in the two other dates in the same format and added the record to the database.  The form's table is user-defined. 
    I dismissed the form then brought it back up loaded with the new record.  The date that was entered by the function appeared in USA format (mm/dd/yy).  The dates that were typed in appeared in the Business One format (dd/mm/yy).  This of course is not consistent.
    When I looked at what got into the database, the formats were the opposite.  Weird!  To make matters really confusing, I run an SQL statement within SQL Server Mgt Studio, and use the WHERE clause to filter on the date that was based on the function.  It didn’t matter what format I used for the WHERE clause, the record came up.  Does anyone have any idea about how I can ensure that I always use the correct date format for SQL statements passed by Business One to SQL Server regardless of where in the world the application is being run?
    Thanks,
    Mike

    Ian,
    Here's what I'm concerned about:  I’m using the date in a “WHERE” clause.
    Assume the date is Aug 3, 2007.
    "SELECT * FROM Table WHERE StartDate > ‘8/3/2007’"
    OR
    "SELECT * FROM Table WHERE StartDate > ‘3/8/2007’"
    If the client machine is set up as USA, the today function will provide the date as formatted in the first query.  If the database server is setup as let’s say the UK, I believe that SQL Server query parser will interpret the date as Mar 8, 2007.
    If the client machine is set up as UK, the today function will provide the date as formatted in the second query.  If the database server is setup as let’s say USA, I believe that SQL Server query parser will also interpret the date as Mar 8, 2007.
    In both cases it would be wrong.
    I know I could use the DATEPART function to get the three parts and this will make the code indifferent to the localization specs of the client machine.  I need to then be able to concatenate those date parts for the “WHERE” clause so that the localization specifications of the database server don’t matter.
    Thanks,
    Mike

  • Date Format in servlet when i insert into database

    I am inserting data into database through servlet, but i am getting NumberFormat Exception, and my datatype in database is DATE ,when i typecast my day and year because they r in int and changing into String,still i am getting the same error .So please can any one tell me where to cahnge the format of date and how to type cast to my Date format of database.
    Thanks,
    lalitha

    My code is:import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.text.*;
    import java.sql.Date;
    import java.util.*;
    public class RegisterServlet extends HttpServlet
         Connection con;
         PreparedStatement ps;
    public void init(ServletConfig sc) throws ServletException
         try
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         con=DriverManager.getConnection("jdbc:odbc:plk","scott","tiger");
         System.out.println("connection created");
         catch(Exception e)
         System.out.println(e);
    public void doPost(HttpServletRequest req, HttpServletResponse res)
         try
         res.setContentType("text/html");
         PrintWriter pw= res.getWriter();
    String ulogin=req.getParameter("login").trim();
    String uph1=req.getParameter("ph1").trim();
    int ph1=Integer.parseInt(uph1);
    String upass=req.getParameter("pass").trim();
    String uph2=req.getParameter("ph2").trim();
    int ph2=Integer.parseInt(uph2);
    String cpass=req.getParameter("cfm").trim();
    String uweb=req.getParameter("web").trim();
    String ufirst=req.getParameter("first").trim();
    String uaddress=req.getParameter("address").trim();
    String umiddle=req.getParameter("middle").trim();
    String ucity=req.getParameter("city").trim();
    String ulast=req.getParameter("last").trim();
    String uzip=req.getParameter("zip").trim();
    int zip=Integer.parseInt(uzip);
    String ud=req.getParameter("Aday").trim();
    String um=req.getParameter("Amonth").trim();
    String uy=req.getParameter("Ayear").trim();
    SimpleDateFormat din=new SimpleDateFormat("dd-mm-yyyy");
    SimpleDateFormat dout=new SimpleDateFormat("yyyy/mm/dd");
    String txtDate="2001-07-07";
    Date date=din.parse(txtDate);
    java.sql.Date dt=new java.sql.Date(txtDate);
    dout.format(dt);
    String usex=req.getParameter("sex").trim();
    String uemail=req.getParameter("email").trim();
    String ust=req.getParameter("st").trim();
    String ucty=req.getParameter("cty").trim();
    ps=con.prepareStatement("insert into Userdetails values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    ps.setString(1,ulogin);
    ps.setString(2,uph1);
    ps.setString(3,upass);
    ps.setString(4,uph2);
    ps.setString(5,cpass);
    ps.setString(6,uweb);
    ps.setString(7,ufirst);
    ps.setString(8,uaddress);
    ps.setString(9,umiddle);
    ps.setString(10,ucity);
    ps.setString(11,ulast);
    ps.setString(12,uzip);
    ps.setDate(13,dt);
    ps.setString(14,usex);
    ps.setString(15,uemail);
    ps.setString(16,ust);
    ps.setString(17,ucty);
    int i=ps.executeUpdate();
    if(i==1)
    pw.println("<h3><center> Thankyou! Your details have been stored. </center></h3>");
    res.sendRedirect("http://localhost:8080/SeekLogin.html");
    pw.close();
    else
         pw.println("<h3><center>Sorry! you are not registered properly. </center></h3>");
    pw.close();
    catch(Exception e)
         System.out.println(e);
    Can anyone look this code and help me out where i am doing the mistake.
    Thanks.

Maybe you are looking for

  • Another Failed CS5 Install in Windows 7

    I have seen many users post similar problems as mine. The StartSrvice fails then the certain values aren't set in the database that lead to fatal SQL errors. The thing is CS5 had been installed  and running on this same machine before. I simply had t

  • Trouble compiling packages

    I have classes written and would like to package them. I thought that I did it right, but then when I used the import statement in a program the error was that the package did not exist. Could someone give me the steps in getting it right. Thank you

  • Having trouble opening camera raw files. Already downloaded Camera Raw Update for Photoshop CS5. I have a pc.

    Please Help? Having trouble opening camera raw files. Already downloaded Camera Raw update. I have a pc.

  • Can I upgrade iWorks'08 to iWorks'09 on Mac OS 10.7.5?

    I have iWorks'08 (Pages 3.0.3, Numbers 1.0.3 , Keynote 4.0.4) on my MacBook Air using Mac OS 10.7.5.  I bought a new iMac (10.10.03) with Pages 5.5.3, Numbers 3.5.3, Keynote 6.5.3). When I try to open a document, it says I need to save them in iWorks

  • Changing Window title programmatically

    I'd like to change the Windows title of a 10g Form whenever the user moves to a different canvas. I know I can change the title with the Set_Window_Property built-in but how can I detect when the canvas has changed?