PDA

View Full Version : Ext.Date + unix-timestamp?



tobiu
29 Jun 2007, 8:22 AM
hi together,

i just looked at the class Ext.Date and have not seen any possibilities to work with unix-timestamps.

like:


function renderDate(value){
var dt = new Date();
dt = Date.parseDate(value, "timestamp");
return dt.format('Y-m-d h:i:s');
}

if i haven't missed it, it would be nice if this gets implemented!

kind regards, tobiu

p.s.: i don't need help to convert it by myself.

mystix
29 Jun 2007, 11:14 AM
or you could be nice and add it to the list of standard date / time patterns provided in the docs :D :
Here are some standard date/time patterns that you might find helpful. They are not part of the source of Date.js, but to use them you can simply copy this block of code into any script that is included after Date.js and they will also become globally available on the Date object. Feel free to add or remove patterns as needed in your code.

Date.patterns = {
ISO8601Long:"Y-m-d H:i:s",
ISO8601Short:"Y-m-d",
ShortDate: "n/j/Y",
LongDate: "l, F d, Y",
FullDateTime: "l, F d, Y g:i:s A",
MonthDay: "F d",
ShortTime: "g:i A",
LongTime: "g:i:s A",
SortableDateTime: "Y-m-d\\TH:i:s",
UniversalSortableDateTime: "Y-m-d H:i:sO",
YearMonth: "F, Y"
};

Example usage:

var dt = new Date();
document.write(dt.format(Date.patterns.ShortDate));

eseguin3
12 Jul 2007, 9:23 AM
I'm running into a similar need to convert timestamps, but I don't really understand how I would go about doing it myself. I'm getting a number like 1160094261000, and I need to display it as a standard date. Would anyone mind stepping me through that process?

tobiu
12 Jul 2007, 1:35 PM
i "workarounded" it and only solved it at the server-side:

for example php has functions to convert date-formats from unix-timestamp to others and back. more global, you could even use the timestamp / datetime - formats in a (my)sql database for the specific needed values.

if it has to be converted on the client, i would search for the php-functions (or of another open source language) and convert them to js.


kind regards, tobiu