private function formatDate(d:Date):String
{
var now:Date = new Date();
var diff:Number = (now.time - d.time) / 1000; // convert to seconds
if (diff < 60) // just posted
{
return "Just posted";
}
else if (diff < 3600) // n minutes ago
{
return (Math.round(diff / 60) + " minutes ago");
}
else if (diff < 86400) // n hours ago
{
return (Math.round(diff / 3600) + " hours ago");
}
else // n days ago
{
return (Math.round(diff / 86400) + " days ago");
}
}
Tag Archive for date
ActionScript function for turning a date into a time interval
PHP format mysql date
function format_date($original='', $format="%d.%m.%Y")
{
return (!empty($original) ? strftime($format, strtotime($original)) : "" );
}
Current Year – Crystal Reports XI
stringVar yr := "" & Year(CurrentDate); MonthName (Month (CurrentDate)-1) & " " & Replace(Left(yr,5), ",","")
Simple JS Calendar
This is very easy to use JavaScript Calendar Control with so many customization option. Date format can be change as different database support different date formats. It also supports multiple instances on same time and all the instances are completely independent with others. It is compatible will all major browsers and different style sheets can be defined to all different instances means every instance can be show in different color scheme on the same page. It also support expiry date feature so you can prevent users to select past dates. There are lots of other customization options as well.
Display Page Date – Concrete5
<?php echo $c->getCollectionDatePublic("F j, Y") ?>
isDateValid – Validate a date in javascript
/**
* Check if a date is valid
* @return bool
* @author Mardix
* @since: June 30 2009
*/
isDateValid = function(year,month,date){
if(year && month && date){
if(month==2){
if((year%4 == 0) && date>29)
return false
else if((year%4!=0) && date > 28)
return false;
}
if((month!=2 && month!=8) && ((month%2 != 1) && date>30))
return false;
else
return true;
}
else
return false;
}
Copydate
<?php
/**
* Copydate
* Returns a year for a copyright section of a website
* Return is in the format starYear-currentYear (e.g. 1999-2009)
* Give the parameter for startYear, currentYear is automaticly filled
* If the startYear is the same as the currentYear or higher currentYear is returned
* If startYear is not a valid year, currentYear is returned
*
* @param string|int $starYear The year when the content was created
* @return string The parsed output as described
*
* @copyright (c) 2009, neobird
* @license <a href="http://www.opensource.org/licenses/mit-license.php" >http://www.opensource.org/licenses/mit-license.php</a> MIT license
*
* @version 2
*/
function copydate($startYear) { //code:neobird-copydate-2/date-copyright-year
return (!ctype_digit((string)$startYear) || $startYear >= date('Y')) ? (string) date('Y') : $startYear.'-'.date('Y');
}
?>
actionscript – date object
// create variable dateNow with the current date var dateNow = new Date(); // create variable with specified date var dateBirthday = new Date(1987,2,22); // create variable with date from number var dateFromNumber = new Date(543387600000); // create variable with specified date+time var dateBirthTime = new Date(1987,2,22,1,32); // find a difference between two dates EG. find the number of days til next NYE: // get current year, make date using that with December (month=11), day 31 var NYEdate = new Date((new Date()).getFullYear(), 11, 31); var nowdate = new Date(); // convert difference in milliseconds to days var nDiffDays = Math.floor((NYEdate - nowdate)/86400000); trace(nDiffDays);
Display Current Year
<?php echo date("Y") ?>