Jump to content

Recommended Posts

Something like this? (I didn't verfiy this)

 

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()

currentDate = year + "-" + month + "-" + day

if (minutes < 10){
minutes = "0" + minutes
}
thetime = hours + ":" + minutes + " "

if (hours > 11) {
ampm = "PM"
} else {
ampm = "AM"
}
fulldatetime = currentDate + " " + thetime + " " ampm

If you're using AJAX, then I'm assuming you're connecting to a PHP script. Why not just have PHP generate the date from there? Or if you want the date to be selectable / relative to the client-time, then you could pass in a unix timestamp (which is much easier to generate with JS) and again let PHP handle the formatting.

I agree.  I would always use PHP instead of javascript if possible.

both have there pros and cons

Care to elaborate?

well its a situational kind of thing...it depends what you need to be done to declare which language would be better suited for you...i wouldnt go as far as saying that I would always use PHP instead of js...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.