Converting a JavaScript timestamp into a human-readable date and time using as.POSIXct in R

Is there a way to convert a timestamp from this format into a readable human date?

I have generated the timestamp using JavaScript:

Date.now();

An example of the output is:

1468833354929

After storing it in a database, when I attempt to convert it using R:

date <- as.POSIXct(1468833354929, origin="1970-01-01", tz="Asia/Singapore")

The result I get is:

48515-06-24 09:15:29 SGT

However, the expected output should be:

2016-07-18 09:15:29 SGT

Do you have any suggestions on why this is happening and how I can achieve the correct human-readable date-time format?

Answer №1

The time unit is in milliseconds. To convert to seconds, simply divide by 1000.

R> as.POSIXct(1468833354929/1000, origin="1970-01-01", tz="Asia/Singapore")
[1] "2016-07-18 17:15:54 SGT"

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

Issues with AngularJS ng-click functionality not functioning properly within a jQuery Dynatable grid display

Currently, I am in the process of creating an HTML file with ng-repeat functionality. Here is a snippet of my code: var li = '<div ng-repeat="list in viewsList">...</div>'; Following this, I utilize the following lines of code: va ...

Efficiently sift through a vast assortment using a filtering method

Currently, I am developing an application similar to Uber which involves managing a collection of drivers with their current positions (latitude and longitude). One specific requirement is to find drivers who are within a 200-meter distance from the user& ...

What strategies can be used to stop elements from reverting to their original state?

Hey there, I'm currently experimenting with animation and trying to create a cool two-step effect: 1. elements falling down and 2. pulsating on click. However, I've run into an issue where after the clicking action, the elements return to their o ...

How can I troubleshoot email validation issues in Vue.js?

<button type="submit" class="register-button" :class="(isDisabled) ? '' : 'selected'" :disabled='isDisabled' v-on:click=" isFirstScreen ...

What is the reason for placing a ReactJS component, defined as a function, within tags when using the ReactDom.render() method?

As someone who is brand new to ReactJS and JavaScript, I am struggling to grasp the syntax. The component I have created is very basic: import React from 'react' import ReactDom from 'react-dom' function Greetings() { return <h1&g ...

Transferring an array from PHP to jQuery through the use of AJAX

My JavaScript code communicates with a PHP page to retrieve data from a database and store it in an array. Now, I would like to use jQuery to loop through that array. This is how the array is structured: Array ( [0] => Array ( [image] => articl ...

Is the AngularJS application failing to transmit data accurately to Node.js?

I've been grappling with this issue for a few days now and I can't seem to pinpoint the problem. As someone relatively new to the MEAN stack, I might be overlooking something obvious. I followed the boilerplate code from mean.io for both the back ...

Establish a connection between the MySql database in WHM (phpmyadmin) and a node.js application

Our team has been working on setting up the database connection with Mysql using node.js in Cpanel. Although I didn't create the database myself, I have all the necessary information such as the host, user, password, name of the database, and port nu ...

Develop a custom input field feature that utilizes both JavaScript and CSS

I really appreciate the feature that allows me to resize the textarea by simply clicking and dragging on the slanted lines in the lower right hand corner. However, I am looking for a way to apply CSS styles to text which is not possible with a textarea. ...

Obtain scope in AngularJS using object ID

Is it possible to retrieve the specific scope of an object by accessing it through an ID? I am currently using angular ui tree for a navigation menu. However, I face an issue where after adding a subitem and saving the navigation into a mysql database, th ...

Leverage Express.js route variables for universal access

I'm currently working on integrating the Spotify API with my express.js server and facing a challenge in accessing an Authorization code from a URL parameter. I've managed to retrieve this value using let code = req.query.code within the callback ...

Display some text after a delay of 3 seconds using setTimeOut function in ReactJS

When using React JS, I encountered an issue where I am able to display text in the console after 2 seconds, but it is not appearing in the DOM. const items = document.getElementById("items"); const errorDisplay = () => { setTimeout(function () { item ...

Multiple 'keydown' events are accumulating with Ajax activated

When the search field is focused, I am loading JSON into the browser and then iterating over the JSON objects to find real-time results 'on keydown'. The issue I'm encountering is detailed in the console after the initial block of code Aja ...

Turn off automatic zooming for mobile device input

One common issue observed in mobile browsers is that they tend to zoom in on an input field or select drop-down when focused. After exploring various solutions, the most elegant one I came across involves setting the font-size of the input field to 16px. W ...

When attempting to call a bundle file using browserify from React, an unexpected character '�' Syntax error is thrown: react_app_testing/src/HashBundle.js: Unexpected character '�' (1:0

Hey there, I'm currently struggling with an unexpected unicode character issue. Let me provide some context: I've created a simple class called HashFunction.js that hashes a string: var crypto = require('crypto') module.exports=class H ...

Issue: C stack usage nearing limit during installation of ggplot2 package

When attempting to install ggplot2, I encountered the following error: > install.packages("ggplot2") Retrieving 'https://cran.rstudio.com/src/contrib/ggplot2_3.4.1.tar.gz' ... OK [downloaded 3 Mb in 0.2 secs] Retrieving 'htt ...

Bootstrap 5 does not support tab navigation functionality

I created a new HTML page, and I encountered an issue while trying to enable tabs using JavaScript. <html> <head> <title>Excel Viewer</title> <link hr ...

Which is quicker: loading JSON via Ajax or loading the entire output through Ajax?

I'm interested in gathering different perspectives on this topic. Currently, I have Jquery initiating a function through ajax which loads data in two ways: The ajax script fetches JSON data from the server itself, then utilizes JavaScript to pars ...

Is there a way to effortlessly zoom in on a Google map with just one mouse click?

Can the Google Maps be zoomed to a specific level with just one click of the mouse? ...

Updating visual appearance with button clicks and unclicks

Is there a way to dynamically update the button image while clicking on it? This is what I have tried: $('.gamebox_minimap_plus').click(function() { $(this).css("background-image","url('gfx/plus2.png')"); }); The image ch ...