I am using a bootstrap datepicker.
While sending the values from datepicker to server my format is mm/dd/yyyy For example: 06/24/2015
When I get the values back from the server ("06/24/2015"), I am trying to fill the datepicker input with 06/24/2015.
For this I am trying to do something like this:
$scope.startDate = ($scope.startDate == null) ? null : new Date($scope.startDate);
Now the $scope.startDate is Wed Jun 24 2015 00:00:00 GMT-0500 (Central Standard Time)
Then I am formatting it to display the date in the datepicker input like this:
$scope.startDate = $filter('date')($scope.startDate,'MM/dd/yyyy');
Now the value is 06/24/2015
Everything works fine but I see a script error saying:
TypeError: Cannot read property 'split' of undefined
at createParser (ui-bootstrap-tpls-0.11.0.min.js:8)
at parse (ui-bootstrap-tpls-0.11.0.min.js:8)
at m (ui-bootstrap-tpls-0.11.0.min.js:8)
at link.k.$render (ui-bootstrap-tpls-0.11.0.min.js:8)
at Object.<anonymous> (angular.js:23295)
at l.$digest (angular.js:14235)
at l.$apply (angular.js:14506)
at l (angular.js:9659)
at S (angular.js:9849)
at XMLHttpRequest.D.onload (angular.js:9790)
I searched a lot of questions and most of them say that this is a bug in datepicker and is available on github master and not yet released.
I wanted to make sure the way I am parsing the dates is correct? Is there a better way to handle this problem and avoid getting the script error?
Normally server data would take a while after your app is initialized. In the mean time datepicker is trying to process a null in ng-model.
While you can certainly wait for a fix from bootstrap, but I think you can consider initialize a date before server data is available, like today's date, or any appropriate date.
$scope.startDate = ($scope.startDate == null) ? new Date() : new Date($scope.startDate);
Edit: I've written a simple datepicker in jsbin but can't seem to get your error in console. Maybe you can update it and reproduce?
Related
I need to configure Statsig flag to return true for 30 days, by setting from and to dates
I am using "check time and date" and I am trying to set before and after time. But its giving invalid error. Not sure what is the mistake. Please guide to resolve this issue
Statsig uses American formats for dates - so MM/DD/YYYY, and XX:XX AM/PM
I think the UI should have a datepicker which enforces this. Here's what mine looks like
I am fairly new to AngularJS and am having an issue with formatting the time object to populate my "time" input field in Android and Firefox. I have spent hours trying to figure out the issue and also utilized AngularJS's documentation to try and figure this out, but have had no luck.
I am dynamically populating an input field from JSON, and the result is always in the following format: 14:57:00.000
I need it to look like this in the input field: 2:57 PM
Here is the link to AngularJS that I have been referring to: AngularJS time input. At the bottom of the page is the plunker to run.
Thank you in advance for any assistance you can provide me.
you can use something like this
{{myTime | date: 'shortTime'}}
I've my date format as '2017-05-16T13:22:01.207Z' and trying to convert to '05/16/17 08:22 AM'. I've tried the following and none of them worked for me in IE, works fine in chrome. Any ideas what is the reason. Did anyone ever face this situation.
Date = '2017-05-16T13:22:01.207Z';
MomentJs Solution:
$moment(Date).format('MM-DD-YY HH:mm A').replace(/-/g,"/")
AngularJs Date Filter:
{{Date | date: 'short'}}
Expected Result: I'm seeing this in chrome, but not in IE
05-16-17 13:22 PM
Hehe, the replace might be the funniest way I've seen someone handling the format() function, which already formats a date as one wishes.
Use
var date = '2017-05-16T13:22:01.207Z';
alert(moment(date).format('MM/DD/YY HH:mm A'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-with-locales.min.js"></script>
Also note!!!
Date is already defined in js (it's the global Date object); so you'd be better off using some different name for your variable - like the similar sounding date; but with a lowercased D/d. (This might be where your error comes from)
I am trying to create a date object of javascript to store current date and time
let now:Date = new Date();
But the below line show error in my intellij as the below error:
TS2304:Cannot find name 'Date'.
I am guessing as Date is javascript object and new Date() is not available in typescript or in my project, its failing.
I am writing angularjs 1.5.9 in typescript, I dont thing is anything related to angularjs.
How to fix this?
Step 1. Simply click on the version displayed in the footer of your visual studio code.
Step 2. Then choose Use Workspace version.
You will be good to go.
try thisvar today = new Date()
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()