0

Ok this is a strange one. Im trying to convert Start and Stop Times from an XMLTV file to Epoch so I can actually parse and use it.

So my goal is to convert the 2 times to Epoch and see if the Current time is either Exactly the Start or Stop time or Inbetween them. Obviously a time string like: 20160421112000 +0100 isnt going to work to check that way but if I could convert it to Epoch it would be Parsable.

The Start and Stop Time's are saved as a String. So how would I manage to convert it to Epoch if I cant even convert it to a Normal DateTime?

Sorry if this is a Noob question I dont normally work with DateTime functions so its quite new to me.

Example Times: Start - 20160421112000 +0100 End - 20160421113500 +0100

EDIT:

Thanks to Plutonix I got it to "work" somewhat. I still have a few issues with it that I have been googling a fix for ages but cant find one working.

This is my current code:

Dim CurrentTime As String = (Date.Now.ToUniversalTime - New DateTime(1970, 1, 1)).TotalMilliseconds
Dim StartTime As String = DateTimeOffset.ParseExact(c.StartTime.ToString, "yyyyMMddHHmmss zzz", New CultureInfo("en-UK")).ToUniversalTime.ToUnixTimeMilliseconds
Dim EndTime As String = DateTimeOffset.ParseExact(c.EndTime.ToString, "yyyyMMddHHmmss zzz", New CultureInfo("en-UK")).ToUniversalTime.ToUnixTimeMilliseconds

If CurrentTime >= StartTime And CurrentTime <= EndTime Then

    'Console.WriteLine(New DateTime(1970, 1, 1).AddSeconds(c.StartTime.ToString).ToLocalTime)
    OnNow.Text = c.Programme.ToString
    StartToEndTime.Text = c.StartTime.ToString

End If

EDIT: Fixed the whole DST issue.

My other issue is that im now trying to use .AddSeconds to convert the Epoch time to a properly Formatted "TIME" I want it to display for example, 8:16pm no +0100 no year month day etc just the Time and PM how can I do that as it keeps saying the value is too big or something like that.

  • Possible duplicate of [Excel VBA: Convert a date string to a Unix timestamp](http://stackoverflow.com/questions/12325948/excel-vba-convert-a-date-string-to-a-unix-timestamp) – Marc B Apr 21 '16 at 18:08
  • @MarcB No that question is technically similar but theyre strings they wish to convert has -'s between the numbers etc mine doesnt and it also has a +100 (Which is timezone stuff) –  Apr 21 '16 at 18:11
  • Easily parsed using `DateTimeOffset.ParseExact` – Ňɏssa Pøngjǣrdenlarp Apr 21 '16 at 18:11
  • @Plutonix Could you link me to a Documentation on its use? –  Apr 21 '16 at 18:13
  • type `DateTimeOffset` into the IDE. Press F1 – Ňɏssa Pøngjǣrdenlarp Apr 21 '16 at 18:13
  • @Plutonix Wow thats nice. Anyway how do I add the time? Do I make it into some "New DateTime" or something? –  Apr 21 '16 at 18:14
  • @Plutonix I tried: `Dim provider As CultureInfo = CultureInfo.InvariantCulture Console.WriteLine(DateTimeOffset.ParseExact(c.StartTime.ToString, "yyyyMMddhhmmss zzz", provider))` But it doesnt return anything in the Console. Any ideas? –  Apr 21 '16 at 18:22
  • @Plutonix Got it working, Still need help doe D: –  Apr 21 '16 at 19:36
  • Why are you messing with Unix Time at all? `20160421112000 +0100` parses to a valid NET DateTime which includes the time. It isnt relative to 1970 at all. – Ňɏssa Pøngjǣrdenlarp Apr 21 '16 at 23:36
  • @ShinyMK - Just a heads up - with all the edits to the question - It is less valid as a question now that the incorrect code has been changed correct code. This is less helpful to other users. For future reference, you can - and are encouraged to add your own answers and then after two days, you can mark the answer as accepted. – David Wilson Apr 22 '16 at 23:58
  • @DavidWilson Yes but it hasnt actually been solved yet but I did manage to find a way around it, Cant remember what I did which is why I didnt post the solution here :/ –  Apr 23 '16 at 04:40
  • I don't meant to be offensive at all here - but now effectively the question isn't helpful to other users searching for an answer - I would politely suggest deleting it now. :) – David Wilson Apr 23 '16 at 18:44

0 Answers0