What is the best way to retrieve time from a MySQL timestamp in ActionScript 3?

I need help displaying an ActionScript 3.0 Timer, based on a timestamp retrieved from MySQL.

Imagine that PHP returns a string like

$my_birthday="2013-05-22 12:30:45"
. I fetched it in ActionScript using a URLLoader, and now I want to present the timer in this format:

My age:
01 hours 01 minutes 42 seconds

Which function should I utilize in:

public function timerHandler(e:TimerEvent)
{
 log_textfield.text = String((new Date()).time) - my_birthday; // I assume I need to convert Date().Time to Unix timestamp, and find a method for calculating time difference.
}

Answer №1

Check out the TimeSpan class in this answer for your coding needs. The following code snippet is designed to help you retrieve the TimeSpan and extract the necessary components for display purposes. Unfortunately, I am unable to test it with Flash on my current device, so please proceed cautiously :)

// Take note that 'new Date()' requires slashes instead of dashes.
my_birthday = my_birthday.replace('-', '/');
var sinceBirthday = TimeSpan.fromDates(new Date(), new Date(my_birthday));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Setting up PhpStorm, Xdebug, and Laravel Configuration

My current development setup consists of PhpStorm 2018.2.1 running on Windows 10. Within this environment, I have successfully configured Homestead Vagrant box for Laravel. The Laravel application is functioning as expected. Recently, I decided to include ...

PHP code malfunctioning within an HTML document

After setting up XAMPP and getting Apache to run successfully, I created a file named helloworld.php in the htdocs folder. However, I encountered an issue where my PHP script within an HTML file was not displaying in the browser. Since I am new to PHP an ...

JavaScript is submitting an incorrect HTML form

I have a PHP script that retrieves items from a database and allows users to vote on them. Each item is associated with an HTML form containing an input text field and a submit button to enter the score. I also have a jQuery script on the same page that up ...

Which is the better choice: JSON file or SQL for storing data?

I am in the process of developing a website that will feature an ajax search functionality. This search will retrieve data either from a JSON file or from a MySQL database. I am unsure which technology would be best suited to store this data. With approxim ...

Tips for utilizing Codeigniter's set_value() functionality within Smarty for repopulating a form

<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" /> Usually works fine in plain HTML, but I am struggling to make it work in Smarty without success so far. <input type="text" name="{$field ...

Create a dynamic editing experience using PHP and AJAX, allowing users to make

Is there a way to update my database table without having to refresh the page? I seem to be encountering issues with my script, as the popup and database selection work fine, but nothing happens when I hit submit. It doesn't redirect me to the edit.ph ...

Laravel request pre-loading system

My Laravel application has a search function on the homepage (home.blade.php) that queries the database and displays results on the results page (results.blade.php). Despite using Elastic search to optimize speed, the search still takes around 10 seconds d ...

Securing the .env file in Laravel: Best practices for safeguarding your

After relocating my project to HOST, I discovered that I am still able to access the .env file by visiting mysite.com/.env. This exposes all the variables and sensitive data within the file. The contents of my .env file are as follows: APP_ENV=local APP_D ...

Search functionality that dynamically updates results as the user types, thanks

I am currently working on implementing a search feature that can assist users when typing in their search queries. The goal is to use Ajax to dynamically show results as the user types. Currently, the functionality requires the user to hit the search butt ...

Inspecting Facebook links

Currently working on a website and interested in incorporating a feature similar to what Facebook has. I'm referring to the link inspector, but I'm not entirely sure if that's its official name. Allow me to provide an example to clarify my r ...

When executed, the code in PHP will display "Terminated" on the terminal without any errors

I've encountered an issue with a script designed to read and insert the contents of a large CSV file into a MySQL database. Despite setting parameters such as set_time_limit(0);, ignore_user_abort();, and ini_set('memory_limit','5120M&a ...

Two instances of a PHP Class created despite employing the Singleton design pattern

Object Oriented PHP Class: if( ! class_exists('MY_CLASS') ) : class MY_CLASS { private static $_instance = null; private static $counter = 0; private function __construct() { self::$counter++; // Perform actio ...

What distinguishes using a period and comma for concatenation with echo versus return?

After some testing, I discovered that the following code works: echo $value , " continue"; However, this code does not work as expected: return $value , " continue"; In both the echo and return statements, using a period instead of a ...

Error: The function 'require(...)' is not a valid function when working with Sequelize in Node.js

I'm just starting out in web development and I'm attempting to build a Full Stack project using Mysql Express React Node.js. However, I've encountered a TypeError issue when using Sequelize with Node.js. Being new to this, I'm having tr ...

It appears that the Apache php module, mod_rewrite, is experiencing some issues with its

I'm currently working on a PHP application hosted on an Apache server. My goal is to utilize the rewrite PHP module to convert URL links like the example below: www.mysite.com/home.php ---> www.mysite.com/home The issue I am facing is that while t ...

How can JavaScript allow access to files outside of a web server environment? Could .htaccess provide a

Currently, I'm facing a challenge with my local server on Mac 10.8. I am trying to serve files such as videos and images from an external hard drive. The path for the external hard drive is HD: /Volumes/ while the web server's path is /Library/Se ...

Is there an alternative method for locating the http referrer?

I currently have a virtual Linux server running Apache2 and PHP, with Tor serving as a hidden service. I am trying to retrieve the HTTP REFERRER information but have found that $_SERVER['HTTP_REFERER'] is not reliable and should not be used. Afte ...

PHP integration with IBM Cloud storage

I am encountering an issue while attempting to establish a bucket and upload files on IBM cloud storage using PHP. I keep receiving an error 405 Method not allowed. Despite reviewing the documentation, which suggests utilizing S3, I have opted for the AWS ...

Load a WordPress page with the help of jQuery

When using jQuery's load function to load a localhost URL (e.g. localhost/wp/contact), everything works perfectly. However, once I upload my site online and change the URL to devric.Co.cc/contact, nothing loads. Could this be related to the htaccess f ...

Wordpress: nginx encountered an error

I set up my wordpress website on DigitalOcean, following a tutorial from this site. The next day, my wordpress site went down and I encountered the following error message: "An unexpected error has occurred. Apologies, but the page you are trying to acc ...