473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

reading in a time that includes milliseconds

112 100+
I was reading in a log file like this that had no milliseconds:
Expand|Select|Wrap|Line Numbers
  1. QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 601650761 block size
  2. QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 606887631 block size
  3. QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 154517966 block size
  4. QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 69220249 block size
  5. QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 575941474 block size
  6.  
and I was outputting it to an excel file like this:
Expand|Select|Wrap|Line Numbers
  1. Class Key    Date    Start Time    End Time    Length(ms)    Block Size    Class    BC (TS)    Product    Class Key    Class Type    Outlier Host    First Tick    Open. Rot.    Open. (ms)    Class Thread #
  2. 606887631    Thu Dec 10    02:01:40    02:01:40    1    1        Unidentified                perfgl15                20
  3. 533476053    Thu Dec 10    02:01:40    02:01:40    1    1        Unidentified                perfgl15                28
  4. 530369105    Thu Dec 10    02:01:40    02:01:40    1    1    ARB    BC20(1)    ARB    530369105    3    perfgl15                24
  5. 69208240    Thu Dec 10    02:01:40    02:01:40    1    1    BLSW    BC20(2)    BLSW    69208240    3    perfgl15                1
  6. 575941474    Thu Dec 10    02:01:40    02:01:40    1    1    CBOU    BC20(3)    CBOU    575941474    3    perfgl15.                24
  7. 601650761    Thu Dec 10    02:01:40    02:01:40    1    1    DNY    BC20(4)    DNY    601650761    3    perfgl15.            28
  8.  
I was going thru the log file, using spaces as new fields and when i got to the time, i was reading in the time using the ':' as a deliminator and reading in the hrs, min and seconds as ints creating a Calendar variable after putting the individual fields into the GregorianCalendar constructor like this:

Expand|Select|Wrap|Line Numbers
  1. if (input.startsWith("QuoteBlockTiming")) {
  2.             boolean sessionSet = false;
  3.             StringTokenizer ST = new StringTokenizer(input, " \t");
  4.             while (ST.hasMoreTokens()) {
  5.                 String thisToke = ST.nextToken();
  6.                 if (thisToke.equalsIgnoreCase("ms:")) {
  7.                     returner.setM_duration(new Integer(ST.nextToken()).intValue());
  8.                     ST.nextToken();
  9.                     ST.nextToken();
  10.                     String strMonth = ST.nextToken();
  11.                     int intMonth = convertMonth(strMonth);
  12.                     Integer intMonthDay = new Integer(ST.nextToken());
  13.                     String strTime = ST.nextToken();
  14.                     StringTokenizer ST2 = new StringTokenizer(strTime, ":");
  15.                     Integer intHour = new Integer(ST2.nextToken());
  16.                     Integer intMinute = new Integer(ST2.nextToken());
  17.                     Integer intSecond = new Integer(ST2.nextToken());
  18.                     ST.nextToken();
  19.                     Integer intYear = new Integer(ST.nextToken());
  20.  
  21.                     Calendar cal = new GregorianCalendar(intYear.intValue(),intMonth,
  22.                           intMonthDay.intValue(),intHour.intValue(),intMinute.intValue(),
  23.                         intSecond.intValue());
  24.  
  25.                    returner.setM_date(cal.getTime());
  26.  
NOW, with milliseconds in the log file that looks like this:
Expand|Select|Wrap|Line Numbers
  1. QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40.364 CST 2009 170.137.15.155 Class key = 601650761 block size
  2. QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40.364 CST 2009 170.137.15.155 Class key = 606887631 block size
  3. QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40.364 CST 2009 170.137.15.155 Class key = 154517966 block size
  4. QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40.366 CST 2009 170.137.15.155 Class key = 69220249 block size
  5. QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40.366 CST 2009 170.137.15.155 Class key = 575941474 block size
  6. QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40.367 CST 2009 170.137.15.155 Class key = 154517966 block size
  7.  
I need to put the milliseconds in the excel file also.

I was thinking about changing the line:
Integer intSecond = new Integer(ST2.nextToken()); INTO
Double intSecond = new Double(ST2.nextToken());

but the GregorianCalendar doesnt have a constructor that has a double argument that it accepts.

I was also thinking about using SimpleDateFormat but i was unsure of how to use that.

I really only need the hours:minutes:seconds.milliseconds in any kind of format

Please help.

Thanks
Dec 10 '09 #1
1 3592
chaarmann
785 Expert 512MB
You are separating the time-string at ":", Before you had for example seconds="40". With the new data you have seconds="40.364".
So you cannot convert that to an integer anymore like before! Just separate this string at "." and assign the first part to seconds, the second part to milliseconds!

Expand|Select|Wrap|Line Numbers
  1. String strSeconds = ST2.nextToken();
  2. StringTokenizer ST3 = new StringTokenizer(strSeconds , "."); 
  3. Integer intSecond = new Integer(ST3.nextToken()); 
  4. Integer intMilliseconds = new Integer(ST3.nextToken());
  5.  
By the way, StringTokenizer is old stuff! Just use Regular Expressions!
With regular expressions, you could do all your splitting at once and less code.
Look here:

Expand|Select|Wrap|Line Numbers
  1.     import java.util.regex.*
  2.  
  3.     CharSequence inputStr = "QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40.364 CST 2009 170.137.15.155 Class key = 601650761 block ...";
  4.     String patternStr = " --- (...) (...) (..) (..):(..):(..)\\.(...) CST (....) ";
  5.  
  6.     Matcher matcher = Pattern.compile(patternStr).matcher(inputStr);    
  7.     if (matcher.find()) {
  8.        String all =         matcher.group(0); // whole String " --- Thu Dec 10 02:01:40.364 CST 2009 "
  9.        String dayInWeek =   matcher.group(1); // returns "Thu"
  10.        String month =       matcher.group(2); // returns "Dec" 
  11.        String dayInMonth =  matcher.group(3); // returns "10"
  12.        String hour =        matcher.group(4); // returns "02"
  13.        String minute =      matcher.group(5); // returns "01"
  14.        String second =      matcher.group(6); // returns "40"
  15.        String millisecond = matcher.group(7); // returns "364"
  16.        String year=         matcher.group(8); // returns "2009"
  17.     }
  18.  
Dec 15 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Andreas | last post by:
Hi! Is it possible to get a time event at a specific time, for instance eight a'clock? My program is running in the background and is minimized to the tray bar. If not, is there a smooth way...
2
by: Guy | last post by:
JavaScript can get time, can it get milliseconds, or actually just tenths of seconds? Thanks for all Guy
26
by: Pravesh | last post by:
Hi: is there a way to get current system time in milliseconds... which functions and headers?? thanks pravesh
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
6
by: Peter | last post by:
I'm interested to know what ideas are out there for reading a parallel port at a constant sample rate while still allowing the user to interact with the GUI. That is, reading it every 10ms for...
2
by: Harlin Seritt | last post by:
How can I take a time given in milliseconds (I am doing this for an uptime script) and convert it to human-friendly time i.e. "4 days, 2 hours, 25 minutes, 10 seonds."? Is there a function from the...
1
by: Benny Schudel | last post by:
hello I've tried to convert some milliseconds to a time format. $ms = 100000 // 1min 40sec echo strftime('%H:%M:%S', $ms/1000); i expect the result is: "00:01:40" but the result ist:...
1
by: samtilden | last post by:
I am writing in C# .NET and am using System.Environment.TickCount (32-bit integer) to get the number of milliseconds since the server was rebooted. The problem is that the server has been up for...
2
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.