Dynamic form and date format in angularjs and node js - angularjs

I hope you can help me I have some doubts about nodejs and angularjs, I'm just starting with this,
I am doing a project in nodejs with angularjs and I found this example of a project
Http://www.aorank.com/tutorial/angular_CRUD_demo/
my question
How can I do that to open another form within a same page as it does in the demo of the link? I hope you can explain me and my question is now about the format of the time, I am trying to get the date and now of this moment and for that use the following
Var datetime = require ('node-datetime');
Var date = Date.now ();
Var datenow = new Date (date);
Var date = datenow.toString ("dd-mm-yyyy HH: mm"). Replace (/ T /, '') .replace (/\..+/, '');
And the consula shows this as a result
Thu May 18 2017 12:17:59 GMT-0400 (CLT)
But I wish it was this way
2017-05-18 12:17:59
And the other doubt how I can make more dynamic and open a form inside another as in the demo link I leave, I hope you can help me and thank you for your time

Related

How to download data from server using date in get methos React?

I'm new with React. I was looking for information for several days to no avail. So I decided to ask you my stupid question.
I have problem with transforming date from DatePicker to date format which than I can use in get request.
I use DatePicker from this https://www.npmjs.com/package/react-datepicker
Sample correct api call:
localhost:8080/api/measurement/12374?date=2020-12-13 12:00
but date from DatePicker look like:
Sun Dec 13 2020 12:00:00 GMT+0100 (Central European Standard Time)
I play with date for example:
let x = new Date();
let x1 = x.toLocaleDateString() + " " + x.toLocaleTimeString();
output: 23/12/2020 09:29:16
but still I have problem with date format and I also don't know how to pass this date correclty to get method, because http request have % instead "space"
http://localhost:8080/api/measurement/12120?date=23/12/2020%2009:48:15
but when I use string as date it work fine and download data:
let value = "12374";
let date = "2020-12-13 12:00";
const request = "http://localhost:8080/api/measurement/" + value + "?date=" + date;
Can someone explain me how can I convert date from DatePicker to format like this 2020-12-13 12:00 and then use it in get method?
I will be very grateful for any answer!
Thank you ;)
you can use momentjs for this task to format date.
https://www.npmjs.com/package/moment
import moment from 'moment'
let date = new Date();
let result = moment(date).format('DD/MM/YYYY hh:mm')
output: 23/12/2020 02:23

how to get value from firebase as date while using moment.js

I'm using firebase as database and momentjs for dates on my Ionic Project.
I save needed dates on firebase but i want to take 2 dates and find difference between them as hours, days etc.
But when i try to take this value's something goes wrong and can not take difference.
Fields on firebase.
My code.
let ms = moment(this.userActivityLoginTime,"DD/MM/YYYY HH:mm:ss")
.diff(moment(this.userActivityLogoutTime,"DD/MM/YYYY HH:mm:ss"));
let d = moment.duration(ms);
console.log(d.days(), d.hours(), d.minutes(), d.seconds());
Your code is wrong. You are trying to subtract bigger value from smaller one. Try code below.
let ms = moment(this.userActivityLogoutTime,"DD/MM/YYYY HH:mm:ss").diff(moment(this.userActivityLoginTime,"DD/MM/YYYY HH:mm:ss"));
let d = moment.duration(ms);
console.log(d.months(),d.days(), d.hours(), d.minutes(), d.seconds());

How to get formatted date using moment.js and convert it into timestamp using angularjs

I have an application where I need to show the date in UI like DD-MM-YYYY hh:mm:ss and again this date to timestamp.
What I have tried:
$scope.dateForUI = moment().format("DD-MM-YYYY hh:mm:ss");
Here I am getting the expected result. But I need timestamp of $scope.dateForUI as well. So I have tried
$scope.dateInTimestamp = moment().unix($scope.get_date_line);
But the console output shows the 1970 date in $scope.dateInTimestamp
My question is how I format my current date and assign it to a variable and again how to get the timestamp for this particular time.
Another thing is it possible to store the time of any timezone in to my $scope.dateForUI variable using moment.js? I need to show the IST time in every browser location.
Very new to moment.js, any help would be appreciated. Thanks in advance.
Try this:
$scope.dateInTimeStamp = moment().unix();
You can use moment-timezone to get values in fixed timezone. For example:
moment.tz("Asia/Kolkata")
Use moment.unix(Number) to get moment object from seconds since the Unix Epoch
Moreover you can use valueOf() to get milliseconds since the Unix Epoch from moment object and .unix() to get seconds.
Here a snippet to show how moment-timezone works and how you can use unix():
// basic angular mock
var $scope = {};
// Current time in India (moment object)
var momNow = moment.tz("Asia/Kolkata");
// Current time in India formatted (string)
$scope.dateForUI = momNow.format("DD-MM-YYYY HH:mm:ss");
// Current time in India as seconds from 1970 (number)
$scope.dateInTimestamp = momNow.unix();
console.log($scope.dateForUI);
console.log($scope.dateInTimestamp);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.7/moment-timezone-with-data-2010-2020.min.js"></script>

Angular JS - YouTube timestamp to UNIX

I'm trying to create an angular filter that converts my UNIX timestamp that I get from a datetimepicker to the YouTube formatted date and vice versa. I've searched everywhere but all I could find is a PHP function... Can someone provide assistance with this?
UNIX: 1440072453
YouTube: 2015-01-08T11:29:40.000Z
Example :
var d = new Date(Date.parse("2012-01-11T20:49:59.415Z"));
d.toString(); // => Wed Jan 11 2012 15:49:59 GMT-0500 (EST)
d.getTime(); // => 1326314999415
From Parsing a Youtube API Date in Javascript

Angular UI datepicker giving me a UTC converted string. How to parse it back to local time accounting for the time difference?

I am currently running into issues with datepicker automatically converting my time to UTC. Is there anything I can pass into datepicker for it to not give me back a UTC converted string? For example the user picks March 19 on the calendar and the returned string would be something like this
'2014-03-19T04:00:00.000Z'
What I want is ->
'2014-03-19T00:00:00-04:00'
What I am trying now (sort of hacking around it) is trying to use moment js to convert it back to my desired (expected) format, but I am having trouble doing so without hardcoding a subtraction in there. I want to be able to convert it from UTC back to local time.
Does anyone know of a solution to this using moment js or angular?
I ran into the same problem and used a filter that adjusts the date and time using the local data to get around it:
filter('adjustDatepicker', ['$filter', function($filter){
var dateFilter = $filter('date');
return function(dateToFix){
var localDate, localTime, localOffset, adjustedDate;
localDate = new Date(dateToFix);
localTime = localDate.getTime();
localOffset = localDate.getTimezoneOffset() * 60000;
adjustedDate = new Date(localTime + localOffset);
return dateFilter(adjustedDate, 'MM/dd/yyyy');
};
}])
Use it like this in your template file:
{{details.datetomodify | adjustDatepicker}}
I think new Date('2014-03-19T04:00:00.000Z').toString() will give you the local version of the UTC time.

Resources