PowWeb Forums - The Perfect Community for the Perfect Host  

Register now to interact with over 11,000 members! Registered users have Posting Privileges, free access to Private Messaging, Email Notifications and more.

Go Back   PowWeb Community Forums > Web Site Design > HTML/CSS/Javascript
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Closed Thread
 
Thread Tools
Old 8-5-08, 04:27 PM   #1
satis
 
satis's Avatar
 
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.
__________________
Satis Clankiller
Clankiller.com Forums
Clankiller.com
PlasmaSky.com
satis is offline  
Old 8-5-08, 05:33 PM   #2
HalfaBee
 
HalfaBee's Avatar
 
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
HalfaBee is offline  
Old 8-6-08, 08:52 AM   #3
satis
 
satis's Avatar
 
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.
__________________
Satis Clankiller
Clankiller.com Forums
Clankiller.com
PlasmaSky.com
satis is offline  
Old 8-7-08, 04:08 PM   #4
satis
 
satis's Avatar
 
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:
var today = new Date();
var 
day = new Date();
day.setTime(el.id 1000);
if(
today.getTime() >= day.getTime() && today.getTime() < (day.getTime() + (60*60*24*1000))){
    var 
hour today.getHours();
    var 
meridiem = (hour 12)? 'am' 'pm';
    
hour = (hour 13)? hour hour 12;
    var 
minutes = (today.getMinutes() < 10)? '0' today.getMinutes() : today.getMinutes();
    var 
baseTime hour ':' minutes meridiem;

That's obviously only a part. el.id was set to the unix time referring to 12am of the day.
__________________
Satis Clankiller
Clankiller.com Forums
Clankiller.com
PlasmaSky.com
satis is offline  
Old 8-8-08, 10:40 AM   #5
troycawley
You are what you is...
 
troycawley's Avatar
 
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?
__________________
-Troy
CAM Web Design
troycawley is offline  
Old 8-10-08, 12:11 PM   #6
satis
 
satis's Avatar
 
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.
__________________
Satis Clankiller
Clankiller.com Forums
Clankiller.com
PlasmaSky.com
satis is offline  
Old 9-4-08, 04:39 AM   #7
amanda12
on hiatus
 
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
amanda12 is offline  
Old 9-4-08, 08:26 AM   #8
satis
 
satis's Avatar
 
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.
__________________
Satis Clankiller
Clankiller.com Forums
Clankiller.com
PlasmaSky.com
satis is offline  
Old 9-4-08, 09:21 AM   #9
Doc C
Just another mook
 
Doc C's Avatar
 
Join Date: Mar 2006
Location: Southern CA
Posts: 5,099
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
Doc C is offline  
Old 9-4-08, 12:43 PM   #10
Croc Hunter
Mod.. with bite..
 
Croc Hunter's Avatar
 
Join Date: Sep 2002
Location: Australia
Posts: 7,305
Reputation: 449
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.
__________________
Croc Hunter MSC :
Croc Hunter is offline  
Old 9-4-08, 12:58 PM   #11
troycawley
You are what you is...
 
troycawley's Avatar
 
Join Date: Nov 2006
Location: Wildwood, NJ
Posts: 245
Reputation: 85
Quote:
Originally Posted by Croc Hunter View Post
amanda12Your comments are not constructive and have earned you a two week ban from the forum..
What a shame, I bet we don't have anyone else from the country of "canda".

I hope she's back soon.
__________________
-Troy
CAM Web Design
troycawley is offline  
Old 9-4-08, 03:05 PM   #12
Doc C
Just another mook
 
Doc C's Avatar
 
Join Date: Mar 2006
Location: Southern CA
Posts: 5,099
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
Doc C is offline  
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:05 AM.


Contents ©PowWeb, Inc. ~ vBulletin, Copyright 2000-2007 Jelsoft Enterprises Limited.