Convert datetime in decimal trough angularjs - angularjs

I would like to ask you, how can I convert decimal number to data in angularJS?
source:
20150911141804
expected:
2015-09-11
I need format this source number inside cellTemplate in ui-grid.
Thanks

If you need to display something you're getting from a data source, like a JSON file or a $http.get(...), then using a filter is the way to go, but I suggest you build a custom one, seeing your format is quite uncommon.
If you need to parse a value entered by a user in, say, an input text, then the right way is to use a custom parser.
If you want to know more you can read the official docs for filters and parsers.

use
<span>{{1288323623006 | date:'yyyy-MM-dd'}}</span><br>
refer to
https://docs.angularjs.org/api/ng/filter/date

Your date has a very strange format.
If you cannot change it (to an UNIX timestamp for example), consider converting your date (as a String) to something like:
20150911141804 => '2015-09-11'
And then create a new date from this String :
var date = new Date('2015-09-11');
Once you have a real Date object, you can format it using angular's native date filter or momentjs.

Related

How to send data to a date textbox with Selenium?

This is the example of my coding that I want to send data to and it works. It's a dropdown element.
driver.FindElement(By.XPath("//ul[#id='select2-ctl00_ContentPlaceHolder1_FormEngine1_mf_18a384bd-8919-4aa7-b953-528b33a775dd_ddlGroup-results']/li[. ='" & roaData(3) & "']")).Click()
Here is the real problem I'm facing. Below here is the code that I want to send data to the element but it is not working. I want to send the data of the date but its not catching the data. The element is a calendar textbox.
driver.FindElement(By.XPath("//input[#id='ctl00_ContentPlaceHolder1_FormEngine1_ctl61_txtDate']")).SendKeys(UCase(Format(roaData(2), "dd MMMM yyyy")))
Any solution guys? Thank you :D
Without seeing the HTML of the target element nor what roaData(2) contains it's not very easy to tell what the issue is, but like most input elements the contents of a textbox is usually located in the value attribute. So instead of SendKeys() I recommend you use setAttribute():
driver.FindElement(By.XPath("//input[#id='ctl00_ContentPlaceHolder1_FormEngine1_ctl61_txtDate']")).setAttribute("value", roaData(2).ToString("dd MMMM yyyy").ToUpper())
Also note that UCase and Format are old functions from the VB6 era, existing only to provide backwards compatibility with that language. I replaced them with the .NET variants DateTime.ToString() (assuming roaData(2) is actually of type Date) and String.ToUpper().

How to format dates from server into JS

It might be a super simple solution, but I am struglling with it for a while now.
I am using angular.js and using input time.
The server returns the following date convention:
shiftStarted = "2017-01-17 19:55:11"
I want to put it as ng-model in the input field:
<input type="time" ng-model="shiftStarted" />
The problem is that input time should receive a valid JS date format,
In order to try to solve it I used this solution I found on the web:
shiftStarted = new Date(shiftStarted.replace(' ', 'T'));
But the following is changing the timezone to UTC.
How can I simply put the date accurately in the input time field without handling tough timezone issues?
Best,
Omri
If your date has been formatted as YYYY-MM-DD, the browser will parse it as an ISO date. (the full format would be 2017-01-17T18:03:26+00:00 at the time of me writing this)
Since no timezone portion was provided (only a date), the browser assumes the timezone is UTC by default.
If you just want to parse a date without bothering with timezones, you could use MomentJS (as suggested by Ananth)
Code would be:
shiftStarted = moment(shiftStarted, "YYYY-MM-DD").toDate();
There is the angular-date directive:
<input type="text" datetime="yyyy-MM-dd HH:mm:ss" ng-model="shiftStarted">
This also include a parser service. New timezone additions too.
https://github.com/eight04/angular-datetime
You could try date.getTimezoneOffset()

DateFormat in angularjs

I wanted to achieve this format: "Saturday, August 30, 2014"
I have this code in my view:
{{masterlist.created_date}}
And the result looks like this:
/DATE(1452842730000)/
What should I do in my controller or in the view? Thanks.
First of all you date should be in correct format
Use datefilter from angular
{{masterlist.created_date | date:'fullDate'}}
Here is the doc
Angular provides many filters, among them one is for date. It provides various format to format your date. Read about them here: date filter: angularjs
But filters can prove performance bottleneck, so its better to avoid them nd format your date on server side.

how to get calendar format date in AngularJs

I have a field "timeStamp:2015-12-08T11:58:46.650-06:00" using this I have to display it has Today and also Tue 11:58AM. How to do this in AngularJs
You should be able to use the built in date filter. So you can display it like this:
{{myDate | date : mediumDate}}
In this case 'mediumDate' is one of the built in formats available.
Check out the various formats here.
https://docs.angularjs.org/api/ng/filter/date
You can do some simple format with the date filter, but for advanced things, like displaying the date/time relative to a concrete moment, you should try MomentJS, wich can handle that and much more.
The functions you're looking for are documented here: http://momentjs.com/docs/#/displaying/fromnow/
It should be easy to set a custom filter with that. Something like this:
app.filter('moment', function() {
return function(dateString) {
return moment(dateString).fromNow();
};
});

How to format dates in different cultures like English, German and Italy

I wanted to format dates in different culture as stated above in Ext Js where i have created one method setDateFormat which accept dateformat "d"(ShortDateFormat) this needs to be formatted in different cultures so for this what code is required in Ext Js, please let me know.
For formatting dates in Ext JS you can use Ext.util.Format.date() method.
As first parameter to this method you will pass date which you want to format and as second parameter date format string.
List of valid format strings and date formatting examples you can find in documentation of Ext.Date class

Resources