Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7510299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:11:29+00:00 2026-05-29T23:11:29+00:00

I’m currently using this to obtain latency: def time_deltas(infile): entries = (line.split() for line

  • 0

I’m currently using this to obtain latency:

def time_deltas(infile): 
entries = (line.split() for line in open(INFILE, "r")) 
ts = {}  
for e in entries: 
    if " ".join(e[2:5]) == "TMsg out: [O]": 
        ts [e[8]] = e[0]  
    elif " ".join(e[2:5]) == "TMsg in: [A]":    
        in_ts, ref_id = e[0], e[7] 
        out_ts = ts.pop(ref_id, None) 
        yield (float(out_ts),ref_id[1:-1],(float(in_ts)*1000 - float(out_ts)*1000))


INFILE = 'C:/Users/klee/Documents/test.txt'
print list (time_deltas(INFILE))

I would like to convert the float(out_ts) to Unix epoch seconds.

I’ve tried the following, but have failed miserably:

int(time.mktime(time.strptime('(out_ts)', '%H%M%S.%f'))) - time.timezone

AND

 t = time.strptime(float(out_ts), "%H%M%S.%f")
        print "Epoch Seconds:", time.mktime(t.timetuple())

AND

d = datetime.strptime("out_ts", "%H%M%S.%f")
        time.mktime(d.timetuple())

AND

pattern = "%H%M%S.%f"
epoch = int(time.mktime(time.strptime(out_ts, pattern))
print 'epoch'

Here’s an example of a time I want to convert:

82128.668173

I’m quite new to Python and any help would be appreciated!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:11:30+00:00Added an answer on May 29, 2026 at 11:11 pm

    The strptime() functions convert strings to times or dates, so if out_ts is a float you will first need to convert it to a string, for example:

    >>> out_ts = 82128.668173
    >>> time.strptime(str(out_ts), '%H%M%S.%f')
    time.struct_time(tm_year=1900, tm_mon=1, tm_mday=1, tm_hour=8, tm_min=21, tm_sec=28, tm_wday=0, tm_yday=1, tm_isdst=-1)
    >>> datetime.strptime(str(out_ts), '%H%M%S.%f')
    datetime.datetime(1900, 1, 1, 8, 21, 28, 668173)
    

    However, you will not be able to convert these dates to an epoch time because epoch time is seconds elapsed since January 1, 1970, and because out_ts only contains hour/minute/second information, you are getting dates/times in 1900.

    You will need to clarify what date you want the epoch time to be calculated for. The time for this example is 8:21:28, but do you want that for 1/1/1970, today’s date, or some other date?

    A simple way to add an arbitrary date to your time would be to use a datetime.timedelta object which represents your time, and then add it to a datetime object for the date you want, for example:

    >>> from datetime import datetime, timedelta
    >>> out_ts = 82128.668173
    >>> dt = datetime.strptime(str(out_ts), '%H%M%S.%f')
    >>> td = timedelta(hours=dt.hour, minutes=dt.minute, seconds=dt.second)
    >>> td
    datetime.timedelta(0, 30088)
    >>> date = datetime(2012, 2, 13)
    >>> full_time = date + td
    >>> full_time
    datetime.datetime(2012, 2, 13, 8, 21, 28)
    >>> epoch = time.mktime(full_time.timetuple())
    >>> epoch
    1329150088.0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.