Amit
asked on
help with a regular expression
Hi,
I am passing the following argument
dateheader = "09/24/2009 15:16:32.099";
to the regular expression below
strsecond = String.valueOf(dateheader. replaceAll (".+[\\ ]+([0-9]{1,2}):([0-9]*):([ 0-9]*):(.+ )","$3"));
so that I can get the seconds in this case the answer should be 32. But I am getting the following output
09/24/2009 15:26:33.309
Could someone please fix the regular expression for me.
Also is there another cleaner way to handle dates. Like get the date part, year part , etc
I am passing the following argument
dateheader = "09/24/2009 15:16:32.099";
to the regular expression below
strsecond = String.valueOf(dateheader.
so that I can get the seconds in this case the answer should be 32. But I am getting the following output
09/24/2009 15:26:33.309
Could someone please fix the regular expression for me.
Also is there another cleaner way to handle dates. Like get the date part, year part , etc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(and then of course your seconds are atoms[atoms.length - 2]
ASKER
Hi CEHJ,
Could you please give me the whole regex. While I explore the datepart funcitonality. I don't know regex and I got this as maintenance work :-(
thanks
-anshu
Could you please give me the whole regex. While I explore the datepart funcitonality. I don't know regex and I got this as maintenance work :-(
thanks
-anshu
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm really unclear as to why you want to replaceAll - it's the worst solution, but:
dateheader = dateheader(".*:(\\d+).*", "$1");
dateheader = dateheader(".*:(\\d+).*", "$1");
Oops
dateheader = dateheader.replaceAll(".*: (\\d+).*", "$1");
dateheader = dateheader.replaceAll(".*:
ASKER
both of you are god
:-)
Yes. Use a DateFormat to set the Date on a Calendar