|
| Register now to interact with over 11,000 members! Registered users have Posting Privileges, free access to Private Messaging, Email Notifications and more. |
|
|||||||
![]() |
|
|
Thread Tools |
|
|
#1 |
|
Join Date: Oct 2002
Location: Dallas
Posts: 2,914
Reputation: 311
|
javascript's date() and the unix timestamp
Is there some way to convert a Unix timestamp into a javascript date() object or vice versa? Basically I currently have a unix timestamp available to js and I need to see whether that timestamp refers to today. If I can either get the unix timestamp into a date object or the reverse, I can figure out the rest myself.
My alternative would be to go back into the PHP side of things and squirt a non-unix timestamp into js, but that's dirty. The unix timestamp is already available so I'd prefer to use that. Some googling left me more confused than anything. |
|
|
|
|
#2 |
|
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 7,266
Reputation: 340
|
Maybe something like this?
var newDate = new Date( ); newDate.setTime( unixtime*1000 ); dateString = newDate.toUTCString );
__________________
I don't suffer from laziness, I enjoy every minute! Edit your php.ini here http://members.powweb.com/member/cgi...nt/PHPplus.bml |
|
|
|
|
#3 |
|
Join Date: Oct 2002
Location: Dallas
Posts: 2,914
Reputation: 311
|
oh... so the javascript epoch is equivalent to the unix epoch? I guess that does make things easier. I'll play with that, thanks.
|
|
|
|
|
#4 |
|
Join Date: Oct 2002
Location: Dallas
Posts: 2,914
Reputation: 311
|
thought I'd just post back to say that Halfa was on the money. Here's a code snippet showing it in action (sorta).
PHP Code:
|
|
|
|
|
#5 |
|
You are what you is...
Join Date: Nov 2006
Location: Wildwood, NJ
Posts: 245
Reputation: 85
|
Thanks for posting back. That is good information W/R/T times in PHP and JS.
But just avoid confusion: I think you meant Javascript code (not PHP) above, yes? |
|
|
|
|
#6 |
|
Join Date: Oct 2002
Location: Dallas
Posts: 2,914
Reputation: 311
|
hah...yes...that code above is javascript. I only included it in a php codeblock because it color codes it.
|
|
|
|
|
#7 |
|
Registered
Join Date: Aug 2008
Location: canda
Posts: 4
Reputation: 0
|
I've been using Unix since before you were born (I can tell by the fact that you haven't learned to use the SHIFT key), and have no idea what you mean by a "unix timestamp" and don't have any inclination to look at mysql documentation to see what they think it is.
Give an example of what you want. Last edited by Doc C; 9-4-08 at 09:21 AM.. Reason: non-PowWeb hosted site signature removed per forum policy |
|
|
|
|
#8 |
|
Join Date: Oct 2002
Location: Dallas
Posts: 2,914
Reputation: 311
|
Wow, you sure have quite a bit of attitude for a whole lot of not posting. Please reread the thread, you'll see that the answer was already provided. Additionally, from actually reading the thread rather than jumping to conclusions, you may realize that by 'Unix Timestamp' I'm referring to the Unix epoch.
|
|
|
|
|
#9 |
|
Just another mook
Join Date: Mar 2006
Location: Southern CA
Posts: 5,100
Reputation: 310
|
Signatures are earned and non-PowWeb hosted signatures are not allowed.
__________________
"You don't really understand human nature
unless you know why a child on a merry-go-round will wave at his parents every time around -- and why his parents will always wave back." -William D. Tammeus |
|
|
|
|
#10 |
|
Mod.. with bite..
Join Date: Sep 2002
Location: Australia
Posts: 7,295
Reputation: 442
|
Wow alright, I just got around to reading this thread - kudos to Halfabee and Satis for posting a solution, thank-you.
amanda12: Flaming people here will usually earn you a ban no matter who you are. Satis is a very knowledgeable constructive member here. Your comments are not constructive and have earned you a two week ban from the forum. Please think twice before posting non-constructive comments in future. |
|
|
|
|
#11 | |
|
You are what you is...
Join Date: Nov 2006
Location: Wildwood, NJ
Posts: 245
Reputation: 85
|
Quote:
I hope she's back soon. |
|
|
|
|
|
#12 |
|
Just another mook
Join Date: Mar 2006
Location: Southern CA
Posts: 5,100
Reputation: 310
|
Uh, the IP traces back to broadband out of India.
__________________
"You don't really understand human nature
unless you know why a child on a merry-go-round will wave at his parents every time around -- and why his parents will always wave back." -William D. Tammeus |
|
|
![]() |
| Thread Tools | |
|
|