Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the time from a date string

How do I get the time from the date string using JavaScript.

My datestring is in the following way: 2013-04-08T10:28:43Z

How to split the time in hours and minutes format. I want to show the activity stream in the following way:

xxx has updated 2hrs ago
yyy has updated 3min ago

like image 585
vishnu Avatar asked Apr 10 '13 06:04

vishnu


People also ask

How do you find time from time string?

SELECT STR_TO_DATE( "Wednesday, 10 February 2021, 12:30:20" , "%W, %d-%m-%Y, %T”); The purpose of the STR_TO_DATE function is to convert a text string to a datetime format. The syntax for this function is as follows: STR_TO_DATE(string, format);

How do you convert string to time?

We can convert a string to datetime using strptime() function. This function is available in datetime and time modules to parse a string to datetime and time objects respectively.

What is new date () getTime ()?

The date. getTime() method is used to return the number of milliseconds since 1 January 1970. when a new Date object is created it stores the date and time data when it is created. When the getTime() method is called on this date object it returns the number of milliseconds since 1 January 1970 (Unix Epoch).

How do you parse a date and time with a moment?

js parsing date and time. We can parse a string representation of date and time by passing the date and time format to the moment function. const moment = require('moment'); let day = "03/04/2008"; let parsed = moment(day, "DD/MM/YYYY"); console.


1 Answers

Just create new Date object:

var myDate = new Date("2013-04-08T10:28:43Z");

var minutes = myDate.getMinutes();
var hours = myDate.getHours();
like image 163
Stasel Avatar answered Sep 20 '22 18:09

Stasel