User Login

Help Community Login:

Convert Unix Timestamp to regular time?

4 replies [Last post]
econtent's picture
econtent
Welcome, Unverified New GeekDropper!
Joined: 03/17/2010
Posts: 3
Drops: 5
Mood: Content

Anyone know how to convert a Unix timestamp that looks like this - 1291668351 - into regular time using javascript? Preferably a bookmarklet?

I Averaged: 0 | 0 votes


Read More ...





Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
STaRDoGG's picture
From:
Olympus
STaRDoGG
Head Mucky MuckJoined the Dark SidePremium Member (Gold)I'm a Code Monkey!The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariLinux UserMac UserWindows UserI donated to GeekDrop simply because I love it!Booga Booga BoogaI took a bite of the AppleFormer Phrozen Crew MemberI'm MagicMember of VileThe Dr. put the stem on the apple!The JokerSomeone thinks you're udderly delightful!
Relationship Status:
Single & Not Looking
Joined: 01/14/2009
Posts: 2566
Drops: 3023
Mood: Energetic
Re: Convert Unix Timestamp to regular time?

Here's some code to convert a Unix timestamp into your own time. And since this is a Beginner's site, I'll also show how to add it to your bookmarks for those that may not already know.
  1. In Firefox, click your Bookmarks menu and click on "Organize bookmarks" (or CTRL+SHIFT+B)

  2. Click on "New bookmark..." and save it on your bookmarks toolbar

  3. Type in some name for the new bookmarklet, like "Unix Timestamp Converter", in the Name field (Fig-1)

  4. In the Location field, paste the javascript code below ...

(Fig-1)
javascript bookmarklet unix timestamp converter

To return the normal time info (Fig-3), paste in this code:

javascript:ts = prompt("Unix timestamp:"); date = new Date(ts*1000); alert(date);

Next time you want to convert just click your bookmarklet, paste (or type if you're crazy) the Unix timestamp into the dialog box and click the OK button. (Fig-2)

(Fig-2)
javascript bookmarklet unix timestamp converter

The Result ...

(Fig-3)
unix timestamp converter

If you want to have the time info returned in Universal time (Fig-4), you could use this code instead:

javascript:ts = prompt("Unix timestamp:"); date = new Date(ts*1000); alert(date.toUTCString()); 

(Fig-4)
convert unix timestamp

For more formatting of the output you can check out PHP.net or this page.

"Wisdom cannot be given unless someone asks for it and shows a readiness to receive it."
econtent's picture
econtent
Welcome, Unverified New GeekDropper!
Joined: 03/17/2010
Posts: 3
Drops: 5
Mood: Content
Re: Convert Unix Timestamp to regular time?

Thanks! I'm kind of a newb when it comes to writing javascript...how can I format it to look more like a digital clock? Like 12 hour format?

STaRDoGG's picture
From:
Olympus
STaRDoGG
Head Mucky MuckJoined the Dark SidePremium Member (Gold)I'm a Code Monkey!The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariLinux UserMac UserWindows UserI donated to GeekDrop simply because I love it!Booga Booga BoogaI took a bite of the AppleFormer Phrozen Crew MemberI'm MagicMember of VileThe Dr. put the stem on the apple!The JokerSomeone thinks you're udderly delightful!
Relationship Status:
Single & Not Looking
Joined: 01/14/2009
Posts: 2566
Drops: 3023
Mood: Energetic
Re: Convert Unix Timestamp to regular time?
econtent wrote:

Thanks! I'm kind of a newb when it comes to writing javascript...how can I format it to look more like a digital clock? Like 12 hour format?

No problem, that's why we're here. Smile That link I added at the bottom shows more formatting choices, but here's an example:

Adding .format("M jS, Y g:i:s a") to the Date variable will cause it to spit out a format like this:

convert unix timestamps

To get that, you can use this code:

javascript:ts = prompt("Unix timestamp:"); date = new Date(ts*1000); alert(date.format('"M jS, Y g:i:s a"));



"Wisdom cannot be given unless someone asks for it and shows a readiness to receive it."
econtent's picture
econtent
Welcome, Unverified New GeekDropper!
Joined: 03/17/2010
Posts: 3
Drops: 5
Mood: Content
Re: Convert Unix Timestamp to regular time?

PERFECT! Thanks So much! You rock!

Who's New

asDewt2354 tnw3's picture
SamCritch's picture
part's picture
tricoat's picture
noster's picture
bebiiee's picture
JustLOVETheGeek's picture
jhonzeth's picture
kaushalmalkan11's picture
avinash.5107218's picture
Raez's picture
MondayTuesday09's picture
sabrina_marie's picture
Tallen's picture
aaron420's picture
facebook codes exploits tips tricks Phrozen Crew
All contents ©Copyright GeekDrop 2009-2017
TOS | Privacy Policy