如何在angularJs中显示Json datetime formate,它显示Datetime为" / Date(820434600000)/"
角色代码
app.controller("MyDeptCntrl", function ($scope, MyDeptSer) {
$scope.BtnDept = function () {
var Dept = MyDeptSer.GetDeptData();
Dept.then(function (d) {
$scope.DeptData = d.data;
// $filter('date')(date, format, timezone)
},function(e){
alert('Loading Failed....')
})
}
答案 0 :(得分:0)
使用以下函数首先解析日期
let attributedString = NSMutableAttributedString(string: "Press this link text")
attributedString.addAttribute(NSLinkAttributeName, value: "http://www.google.com", range: NSRange(location: 6, length: 14))
let linkAttributes = [
NSForegroundColorAttributeName: UIColor.greyishBrownColor(),
NSUnderlineColorAttributeName: UIColor.greyishBrownColor(),
NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue
]
agreementsTextView.delegate = self
agreementsTextView.attributedText = attributedString
agreementsTextView.linkTextAttributes = linkAttributes
// Delegate Method
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {
if URL.absoluteString == "http://www.google.com" || URL.relativePath == "http://www.google.com" {
print("Tapped")
}
return false
}
所以
function dateParser(input){
input = input.replace('/Date(', '');
return new Date(parseInt(input,10));
}
答案 1 :(得分:0)
你可以试试这个
{{1}}
答案 2 :(得分:0)
我建议您更改服务器端代码以使用更友好的JSON序列化程序,但如果没有,请尝试:
// You start with /Date(820434600000)/
// substr(6) takes off the /Date( part and pass the number 820434600000 into the parseInt function.
// Note: the parseInt function will ignore the )/ and the end.
var friendlyDate = new Date(parseInt($scope.DeptData.someDateMember.substr(6)));
// Then, you can format it using angular date filter -- for example:
$scope.formattedDate = $filter('date')(friendlyDate, 'MM/dd/yyyy');