I need help generating a timestamp the same way you generate one in flash (actionscript)

new Date().getTime()

That's how you generate it in actionscript, it returns a 13 character int. eg 1202497647515

Dim date1970 As Date = "#1/1/1970 12:00:00 AM#"
Dim datenow As Date = Date.Now

days = DateDiff(DateInterval.Second, date1970, datenow)

With VB.net it returns a 10 character int. eg 1202497717


How can I make the vb one the same as the actionscript one by only editing the vb?

Dani AI

Generated

Short answer: ActionScript's timestamp is milliseconds since the Unix epoch (midnight Jan 1, 1970 UTC). The VB code you were using returns seconds or a formatted date string, so it will look shorter or different. 's formatting only changes appearance; was on the right track with subtracting the epoch.

Use one of these safe VB.NET approaches to produce the same 13‑digit millisecond value that ActionScript/javasript use:

' .NET 4.6+ (recommended when available)
Dim unixMs As Long = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
' Older frameworks: build an explicit UTC epoch and use TotalMilliseconds
Dim epoch As New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
Dim unixMs As Long = Convert.ToInt64((DateTime.UtcNow - epoch).TotalMilliseconds)

Troubleshooting notes:

  • Always use UTC (DateTime.UtcNow or DateTimeOffset.UtcNow). Using local Now will inject your timezone offset and will not match ActionScript's UTC-based value.
  • Use TimeSpan.TotalMilliseconds (and convert to Int64) — do not use the Milliseconds property (that only returns the remainder 0–999).
  • If you already have a seconds-based value, multiply by 1000 and add the current millisecond component (but prefer the epoch subtraction approach for correctness).
  • TotalMilliseconds is a Double; converting to Int64 truncates fractional ms. That is normal and matches how browsers report integer milliseconds.

Implementing either of the code snippets above will produce the same millisecond-since-1970 value that ActionScript returns and resolve the 10-digit vs 13-digit mismatch.

Recommended Answers

All 6 Replies

I need help generating a timestamp the same way you generate one in flash (actionscript)

new Date().getTime()

That's how you generate it in actionscript, it returns a 13 character int. eg 1202497647515

Dim date1970 As Date = "#1/1/1970 12:00:00 AM#"
Dim datenow As Date = Date.Now

days = DateDiff(DateInterval.Second, date1970, datenow)

With VB.net it returns a 10 character int. eg 1202497717


How can I make the vb one the same as the actionscript one by only editing the vb?

you can use the Format(Now"MMDDYYYYhhmmss") this will result in 02192008114618 as your DateDiff result

Thank you for the reply, however that doesn't generate it in the same formate that flash does (javascript also generates it the same)

The code you gave returns
02202008095054

The actionscript returns
1203501047328

Which according to the actionscript documentation is the number of milliseconds from midnight January 1, 1970

The best I can get with vb.net is

VB.net
1203501350

Actionscript
1203501350515

Its almost there but actionscript seems to get 3 extra digits from somewhere, It's driving me insane.

Thank you for the reply, however that doesn't generate it in the same formate that flash does (javascript also generates it the same)

The code you gave returns
02202008095054

The actionscript returns
1203501047328

Which according to the actionscript documentation is the number of milliseconds from midnight January 1, 1970

The best I can get with vb.net is

VB.net
1203501350

Actionscript
1203501350515

Its almost there but actionscript seems to get 3 extra digits from somewhere, It's driving me insane.

Steven, if you take away the ss on the end, it will give you 12 digiits, to the minute. I added the addition of the seconds.

Thanks for your help but that's not giving the correct value.

The actionscript returns the number of milliseconds from jan 1st 1970 to 13 digits.

You code just gives me the date but formatted without any spaces or symbols and not a timestamp.

Try this:
DateTime.UtcNow.Subtract(#1/1/1970#).TotalMilliseconds()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.