double codes
2013-06-27 21:32:10
Hey.
If you wouldn't mind helping me a bit with some code i am struggling with that would be great.
So Zybez Price checker API is pretty much a pain in the ass when it comes to dates.
They use epoch(Linux Time) to calculate the dates of when each item is being added to their database(Dunno why).
To convert the epoch time into a normal date Year/Month/Day/Hour/Minute/Second is no problem at all.
And to get the date to show in my listview is also no problem.
However i want the time to let the user know when the date was added ("7 minutes ago").
Now this is the problem:
The For each won't work by changing the value 2 times.
Main code
The functions i use:
Screenshot:
http://gyazo.com/f78a4fa2f3960c05cc66a2974ca1788e.png
Thanks
If you wouldn't mind helping me a bit with some code i am struggling with that would be great.
So Zybez Price checker API is pretty much a pain in the ass when it comes to dates.
They use epoch(Linux Time) to calculate the dates of when each item is being added to their database(Dunno why).
To convert the epoch time into a normal date Year/Month/Day/Hour/Minute/Second is no problem at all.
And to get the date to show in my listview is also no problem.
However i want the time to let the user know when the date was added ("7 minutes ago").
Now this is the problem:
The For each won't work by changing the value 2 times.
Main code
Private Sub txturl_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txturl.KeyPress
Dim li1 As New ListViewItem
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
Dim TempUrl As String
TempUrl = "http://forums.zybez.net/runescape-2007-prices/api/" + txturl.Text
TempUrl.ToString.Replace(" ", "+")
Try
Dim ResultJSON As String = New WebClient().DownloadString(TempUrl)
ResultJSON = ResultJSON.ToString.Replace("date", "date1")
Dim Ritem As RuneItem = jss.Deserialize(Of List(Of RuneItem))(ResultJSON)(0)
lbpropeties.Items.Clear()
PrintOutAllProperties(Ritem)
For Each ROffer As RuneOffer In Ritem.Offers
li1 = ListView1.Items.Add(ROffer.rs_name)
li1.SubItems.Add(ROffer.Price)
li1.SubItems.Add(ROffer.contact)
ROffer.date1 = EpochToDateTime(ROffer.date1) ' <- This only converts the epoch time to a real date (28/6/2013:03:27:15)
ROffer.date1 = GetTimeAgo(ROffer.date1) ' <- This should have converted it to for example "7 minutes ago" but replaced every item in the column with "00:00:00"
li1.SubItems.Add(ROffer.date1)
lbpropeties.Items.Add("______")
PrintOutAllProperties(ROffer)
Next
ChangeText()
Catch ex As Exception
MsgBox("Something went wrong!")
End Try
e.Handled = True
End If
End SubThe functions i use:
Public Function EpochToDateTime(ByVal EpochValue As Integer) As Date
If EpochValue >= 0 Then
Return CDate("1.1.1970 00:00:00").AddSeconds(EpochValue).AddHours(2)
Else
Return CDate("1.1.1970 00:00:00")
End If
End Function
Public Function GetTimeAgo(ByVal value As Date) As Date
Dim t As TimeSpan = DateTime.Now - value
Dim display As String
If t.TotalSeconds < 60 Then
display = "Less than a minute ago"
ElseIf t.TotalMinutes < 60 Then
display = t.Minutes.ToString() + " minutes ago"
End If
End FunctionScreenshot:
http://gyazo.com/f78a4fa2f3960c05cc66a2974ca1788e.png
Thanks