473,785 Members | 2,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading in a time that includes milliseconds

112 New Member
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 GregorianCalend ar 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.nex tToken()); INTO
Double intSecond = new Double(ST2.nextToken( ));

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

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

I really only need the hours:minutes:s econds.millisec onds in any kind of format

Please help.

Thanks
Dec 10 '09 #1
1 3620
chaarmann
785 Recognized Expert Contributor
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
24496
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 to accomplish this in a different way? Best regards, Andreas Lundgren
2
6271
by: Guy | last post by:
JavaScript can get time, can it get milliseconds, or actually just tenths of seconds? Thanks for all Guy
26
55757
by: Pravesh | last post by:
Hi: is there a way to get current system time in milliseconds... which functions and headers?? thanks pravesh
9
7287
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; Let's declare a constant Int32 m_TimePeriod = 10000;
6
3277
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 example without exception. Is this at all possible? Current tests done show that if the sample rate is 10ms then this is acheived in general, but when another program loads or terminates this 10ms jumps up to 100ms or more. In these tests the code is...
2
10839
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 time module that can do this? Thanks, Harlin Seritt
1
12669
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: "01:01:40"
1
2403
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 over 30 days and the 32-bit integer is coming back negative. Of course, I can extend it with zeros and make it a 64-bit integer, but what will happen after 60 days or so? Will the C# code then loop around through zero and start reporting a
2
2842
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 wireless where I'm working could just be ungodly slow-- which it is.) Is reading a file much more resource/processor intensive than, say, including a .php file? What about the act of creating a simpleXML object? What about the act of checking the...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.