Jul 27, 2008

Converting To Unix Timestamp - Function to convert standard time format to Unix timestamp

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > VB Programming

free web hosting

Converting To Unix Timestamp - Function to convert standard time format to Unix timestamp

Galahad
I don't know how many of you are familiar with IRC development, but all time/date information are saved in unix time stamp format. Unix timestamp is number of seconds elapsed, since 1st january 1970. Unix timestamp is also used in phpBB forums, and possibly in other bulletin boards. It is very convenient for manipulation, mathematical calculations, and other things...

Use these functions to work with Unix time stamps (this is fully working code, just copy/paste it):

CODE
Option Explicit

Private Type SystemTime
       wYear As Integer
       wMonth As Integer
       wDayOfWeek As Integer
       wDay As Integer
       wHour As Integer
       wMinute As Integer
       wSecond As Integer
       wMilliseconds As Integer
End Type
Private Type TIME_ZONE_INFORMATION
       Bias As Long
       StandardName(32) As Integer
       StandardDate As SystemTime
       StandardBias As Long
       DaylightName(32) As Integer
       DaylightDate As SystemTime
       DaylightBias As Long
End Type
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Public Function FromUnixTime(ByVal sUnixTime As Long) As Date
Dim NTime As Date, STime As Date
Dim TZ As TIME_ZONE_INFORMATION
STime = #1/1/1970#
NTime = DateAdd("s", sUnixTime, STime)
GetTimeZoneInformation TZ
NTime = DateAdd("n", -TZ.Bias, NTime)
FromUnixTime = NTime
End Function

Public Function ToUnixTime(ByVal STime As Date) As Long
Dim NTime As Date, sUnix As Date, sUnixTime As Long
Dim TZ As TIME_ZONE_INFORMATION
sUnix = #1/1/1970#
GetTimeZoneInformation TZ
NTime = DateAdd("n", TZ.Bias, STime)
sUnixTime = DateDiff("s", sUnix, NTime)
ToUnixTime = sUnixTime
End Function


I hope this helped someone smile.gif

 

 

 


Reply

iGuest
Would like to see this for VBSCRIPT =) That would really help quite a bit

-Mike

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. vb unix timestamp - 6.25 hr back. (1)
  2. visual basic unix timestamp - 2.62 hr back. (2)
  3. convert unix timestamp to date format using php - 25.85 hr back. (1)
  4. unix timestamp php datediff - 26.95 hr back. (1)
  5. unix time function calculations - 32.78 hr back. (1)
  6. unix date diff - 32.85 hr back. (1)
  7. convert integer unix time - 34.57 hr back. (1)
  8. date formatting unix - 39.55 hr back. (1)
  9. irc unix time converter - 39.60 hr back. (1)
  10. unix convert long to formatted date - 43.59 hr back. (1)
  11. converting long time in vb - 45.21 hr back. (1)
  12. unix timestamp format - 48.79 hr back. (1)
  13. converting a date to unix timestamp in asp vb - 49.18 hr back. (1)
  14. convert date format to different date format unix - 56.25 hr back. (1)
Similar Topics

Keywords : converting, unix, timestamp, function, convert, standard, time, format, unix, timestamp

  1. Log Function
    (2)


      Looking for converting, unix, timestamp, function, convert, standard, time, format, unix, timestamp

Searching Video's for converting, unix, timestamp, function, convert, standard, time, format, unix, timestamp
Similar
Log Function
advertisement



Converting To Unix Timestamp - Function to convert standard time format to Unix timestamp



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE