Here is a simple line of code I am using:
<td style="text-align: center;"> {{ item.StartAt | date:"HH:MM"}}</td>
The data is fetched from database which has a DateTime column. Data is in object form so that I can convert date time to time. Without the Date pipe, the received value on the website is:
1900-01-01T10:00:00.000Z
But with the date pipe, the time received is:
14:01
As you can see there is a difference of 4 hours and 1 minute time. Can someone please tell how can I get exact time? Thank you.
Since Date Pipes have an issue of Timezone in Angular, I went to the database (SQL Server) and there I changed the Stored Procedure to fetch only Time instead of DateTime using convert(varchar, sd.StartAt, 24). Now it is working fine.
capital "M" is month , you need to have
<td style="text-align: center;"> {{ item.StartAt | date:"HH:mm"}}</td>
Related
What I have in my #Entity Person class -
#JsonFormat(pattern="yyyy-MM-dd")
private Date dob;
What I am printing on screen-
<tr ng-repeat="person in vm.persons">
<td>{{person.id}}</td>
<td>{{person.name}}</td>
<td>{{person.location}}</td>
<td>{{person.dob}}</td>
</tr>
the person.dob is showing date 1 day lesser than what exist in the database.
What could be the possible reason ?
Note:
I have dob as date type in database which is Microsoft SQL Server.
The JSON response from REST call returns timestamp which is being converted to yyyy-mm-dd format as shown above.
Example of issue:-
In database dob(s) are:-
dob
1989-05-18
1989-05-18
1970-01-01
on screen showing as below-
Person Dob
1989-05-17
1989-05-17
1969-12-31
Let me know if need more info on the issue.
I would recommend using moment js or something to get UTC date. This is a common problem between server and UI
I have datetime value on database as follow
But following angularJS code display wrong hour in View
<i title="Baxıldı {{item.ViewedDate | date: 'dd.MM.yyyy hh:mm:ss Z'}}"></i>
for example:
I think this error depends on localization, in my country is UTC+4, so 4 hours added to current value.
Please help to solve this problem.
You can add timezone as the third argument when you're using the date filter.
{{ date_expression | date : format : timezone}}
Here's an example if the dates in your database in stored in UTC.
<i title="Baxıldı {{item.ViewedDate | date: 'dd.MM.yyyy hh:mm:ss Z': 'utc'}}"></i>
From the docs:
Timezone to be used for formatting. It understands UTC/GMT and the
continental US time zone abbreviations, but for general use, use a
time zone offset, for example, '+0430' (4 hours, 30 minutes east of
the Greenwich meridian) If not specified, the timezone of the browser
will be used.
I have been using angular date filter to format my time stamp. But it seems it shifts my time stamp by 1 hour and I don't know how to control that.
2015-06-18T23:59:59Z was converted to 19-Jun-2015 00:59:59
I knew it is related to timezone but my time stamp had time zone specified. I don't want to hardcode a time zone in my filter because I don't want to update my application when UK summer/winter time changes.
Could someone advise me please?
Here's example:
http://jsfiddle.net/chfw/5vy5s1ey/1/
<div ng-app>
2015-06-18T23:59:59Z was converted to <font color=red>
{{"2015-06-18T23:59:59Z" | date:'dd-MMM-yyyy HH:mm:ss'}}
</font>
</div>
I believe it's because 'T' and 'Z' refer to UTC timezone and the filter takes that into account and tries to make the necessary adjustments. Not sure entirely on the specifics.
Removing 'T' and 'Z' will treat it like a neutral timestamp and won't make any shifting:
{{"2015-06-18 23:59:59" | date:'dd-MMM-yyyy HH:mm:ss'}}
Fiddle
I am having trouble with date submissions to a database. When date and time are both needed, I parse the values from the database as a timestamp, which gives me the value of the date and time in milliseconds since 1970. Using the AngularJS date filter, I am able to display the value in a user-friendly way.
$filter('date')(1380292078000, 'MM/dd/yyyy hh:mm a'); => 09/27/2013 10:27 AM
But this format as a timestamp when I send the value back to the database, my code throws an error. The database wants the date to be displayed in a different format.
java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss
So I add a second filter to convert the value date representation of the millisecond count (the user might have changed the value), but I am just getting a clone of the first date representation.
$filter('date')('09/27/2013 10:27 AM', 'yyyy-mm-dd hh:mm:ss') => 09/27/2013 10:27 AM
Here is a link to the fiddle I wrote to test this. Are we not able to stack filter conversions on top of each other? I had a thought to convert the first conversion result into milliseconds to use as a source for the second conversion, but I didn't see a method to accomplish this in the date documentation. If that would be the only solution, though, I am sure I could whip something up. Because Java has mostly deprecated functions to work with dates, I feel it would be simpler to handle this on the Javascript/AngularJS side.
The date filter will only work with a JSON date string (see source).
You can get around your problem by converting to a date object:
$scope.date2 = $filter('date')(new Date($scope.date), 'yyyy-MM-dd hh:mm:ss')
See updated fiddle
However... You should be validating and formatting this input on the server side. You can't trust data coming from a javascript application to be in the correct or expected format. I'd recommend just posting back $scope.date and allowing the server to format in your database format. By doing the yyyy-MM-dd hh:mm:ss formatting on the client-side, you're tightly coupling your user interface to database implementation and that's generally considered a bad idea.
How to display a time HH:MM format?
Using SQL 2000
In my Database time column datatype is varchar
Example
Table1
Time
08:00:00
09:00:23
214:23:32
Here I want to take only 08:00, 09:00, 214:23
How to make a query for this condition?
Whilst you could choose to turn the varchar into a datetime and format it there, assuming you do not want rounding, you could could shortcut the process. (Assuming the time format in the varchar is consistent)
select left('08:00:00',5)
Edit : Question altered, now I would use
select substring('243:00:00', 1, len('243:00:00') - 3)
and replace the value I used with the appropriate field
Cheap and cheerful.
I think Andrew was onto a correct solution, just didn't address all of the possibilities:
SELECT LEFT(Time, LEN(TIME)-3)
should trim off the last 3 characters.
Now, if you want to round up, that's another story....