Need get current date and time with my timezone that is UTC-3, in this format 2021-02-05 12:45:00. How is this possible in Angular?
my current ts using
fechaHoy = new Date();
Need get current date and time with my timezone that is UTC-3, in this format 2021-02-05 12:45:00. How is this possible in Angular?
my current ts using
fechaHoy = new Date();
I would recomend the dateFormat module (moment.js is deprecated). Firstly, install the module as follows - always back up your work with Git beforea adding unknown dependencies of course
npm i dateformat
Then call:
//Import Module
let dateFormat = require('dateformat');
//Instantiate New Date & then call func and parse date.
let date = new Date();
var currDate = dateFormat(date, "yyyy, dddd, mmmm dS, h:MM:ss TT");
You could then use currDate to update a field etc.
You can use this function
function formatMyDate(date) {
function minTwoDigits(n) {
return (n < 10 ? '0' : '') + n;
}
return date.getUTCFullYear()+"-"+minTwoDigits(date.getUTCMonth())+"-"+minTwoDigits(date.getUTCDate())+" "+
minTwoDigits(date.getUTCHours())+":"+ minTwoDigits(date.getUTCMinutes())+":"+ minTwoDigits(date.getUTCSeconds())
}
call this function with date object
formatMyDate(new Date())
//output "2021-01-05 15:03:19"