I am using the Jira API, and need the start and end dates for a sprint.
The JSON data I get back is :
{"jodaTimeZoneId":"Europe/Berlin","sprints":[{"id":5,"start":"13082015044305","end":"27082015044305",...
Normally, json returns the date in milliseconds, and you need to deserialize that.
Now however, I can clearly see the date (13-08-2015 & 27-08-2015) followed by some other numbers I don't care about. Is there anyway Angular can get the correct format using | date? Or any other way I can use?
When I use {{13082015044305 | date:'dd-MM-yyyy'}} it returns 21-07-2384. The parsing date format is wrong. So change the format to recognized way.
So I used
input.toString().replace(/(\d\d)(\d\d)(\d\d\d\d)(\d\d\d\d\d\d)/, '$1-$2-$3');
Used it in a custom filter.
app.filter('correctDateFormat', function() {
return function(input) {
return input.toString().replace(/(\d\d)(\d\d)(\d\d\d\d)(\d\d\d\d\d\d)/, '$1-$2-$3');
};
});
Then
Display the date as
{{13082015044305 | correctDateFormat }}
I think you can use
{{ data | filter:options }}
where data is your json and date filter
{{'1388123412323' | date:'MM/dd/yyyy # h:mma'}}
an option like this.
Related
My dataframe looks like
|ID|Notes|
---------------
|1|'{"Country":"USA","Count":"1000"}'|
|2|{"Country":"USA","Count":"1000"}|
ID : int
Notes : string
When i use from_json to parse the column Notes, it gives all Null values.
I need help in parsing this column Notes into columns in pyspark
When you are using from_json() function, make sure that the column value is exactly a json/dictionary in String format. In the sample data you have given, the Notes column value with id=1 is not exactly in json format (it is a string but enclosed within additional single quotes). This is the reason it is returning NULL values. Implementing the following code on the input dataframe gives the following output.
df = df.withColumn("Notes",from_json(df.Notes,MapType(StringType(),StringType())))
You need to change your input data such that the entire Notes column is in same format which is json/dictionary as a string and nothing more because it is the main reason for the issue. The below is the correct format that helps you to fix your issue.
| ID | Notes |
---------------
| 1 | {"Country":"USA","Count":"1000"} |
| 2 | {"Country":"USA","Count":"1000"} |
To parse Notes column values as columns in pyspark, you can simply use function called json_tuple() (no need to use from_json()). It extracts the elements from a json column (string format) and creates the result as new columns.
df = df.select(col("id"),json_tuple(col("Notes"),"Country","Count")) \
.toDF("id","Country","Count")
df.show()
Output:
NOTE: json_tuple() also returns null if the column value is not in the correct format (make sure the column values are json/dictionary as a string without additional quotes).
I am using a payments API in my application and am getting the invoice value with type number
signature.invoice.amount: 10500 (Number)
I tried to use currency pipe {{ signature.invoice.amount | currency: 'BRL': true}} and the transformed value is: $ 10,500.00.
But the transformed value should be $ 105.00 ... how do I get the number of the amount received to a monetary value in 'BRL' with a return of the number type?
Since $105.00 is 10,500 cents, you want to convert it to dollars before transforming it:
{{ signature.invoice.amount / 100 | currency: 'BRL': true}}
Good job storing currency as cents though! That's the way to do it to save yourself errors down the line.
I want to get the current date as a string in the following format:
\/Date(1411762618805)\/
I have been fighting with PowerShell and have tried the following, but it keeps wrapping the object with unwanted properties. I just need the value
Get-Date | ConvertTo-Json
# returns
{
"value": "\/Date(1411762618805)\/",
"DisplayHint": 2,
"DateTime": "Friday, September 26, 2014 4:16:58 PM"
}
Of course if you try to convert back to an object with ConvertFrom-Json you are back with a .NET Date object.
I have gotten closer with
Get-Date | Select-Object -Property Date | ConvertTo-Json
{
"Date": "\/Date(1411704000000)\/"
}
But it is still wrapped in a Date child property. At the end of the day all I want is a string with Microsoft's ugly JSON format.
I only want to use the built in .NET JSON serializers if possible.
There are two problem properties here, DateTime and DisplayHint and both require a different solution. The DateTime property is a ScriptProperty attached by the extended type system, so it exists on all DateTime objects automatically. You can remove it from all DateTime objects in the current session via Remove-TypeData
Get-TypeData System.DateTime | Remove-TypeData
The DisplayHint property is a NoteProperty that is added by the Get-Date cmdlet. I know of no way to suppress this from serialization. You can remove it explicitly from the DateTime:
Get-Date | foreach { $_.PSObject.Properties.Remove("DisplayHint"); $_ } | ConvertTo-Json
which will output
"\/Date(1411846057456)\/"
This is current date and time, if you only want the date you can do this
Get-Date | select -ExpandProperty Date | ConvertTo-Json
Here we don't have to remove the DisplayHint because it was not attached by Get-Date.
Don't even get me started on the hoops you will have to jump through to convert back to the proper date time object.
So, the wonderful thing about JSON dates is... nothing. They are evil, and deserve to be punished.
So, what is a JSON date? It is the number of milliseconds since Unix Epoc (Jan 1, 1970), well, UTC time that is. So, that's great and all, but how do we get that without using the ConvertTo-JSON cmdlet? Easiest way I know of is this:
[int64]([datetime]::UtcNow)-(get-date "1/1/1970").TotalMilliseconds
That will get you the current date and time formatted for JSON. If you want a specific date or date/time you could do it, but you have to adjust for time zone, which we can do, it just gets long:
$target = "2/2/2014 6:32 PM"
[int64]((get-date $target).addhours((([datetime]::UtcNow)-(get-date)).Hours)-(get-date "1/1/1970")).totalmilliseconds
1391391120000
That would be the kick-off time for the last Super Bowl.
I know this is old but Google led me here. I'm using Invoke-RestMethod to send/receive JSON data, including timestamps in the /Date(1411704000000)/ format. I managed to convert from PowerShell to JSON using the following:
[System.DateTime]$(Get-Date).DateTime
Example:
#{DateTime = [System.DateTime]$(Get-Date).DateTime} | ConvertTo-Json
Returns:
{
"DateTime": "\/Date(1484023637000)\/"
}
Try use [System.Datetime]::Now instead Get-Date cmdlet
My database stores two dates in the mysql DateTime format YYYY-MM-DD HH:MM:SS. When I get this data (with other strings etc), I want to convert it to another format, maybe DD.MM.YYYY HH:MM:SS and display it on my view in a table cell. My database dates are called date_begin and date_end.
Better, when I get this dates from database, convert it to DD.MM.YYYY format, separate the date and the time, store the time in a custom string ("HH1:MM1 - HH2:MM2") and bring both on my view.
How can I achieve this? I found some examples to convert on the view, not in the controller, but I think this is not good for MVC.
Not sure where you've gotten the impression that "formatting the date in the view is not good for MVC", because that's not a problem whatsoever.
If you're using Eloquent Models you can do it very easily:
1. Add the columns to the $dates property in your model class:
protected $dates = ['date_begin', 'date_end'];
This will ensure that the values get mutated to Carbon instances.
2. In your view files you can use the format method that Carbon offers like so:
<!-- To use only the date with the given format -->
{{ $item->date_begin->format('Y.m.d') }}
<!-- To use only the time with the given format -->
{{ $item->date_begin->format('H:i:s') }}
<!-- To use both date and time with the given format -->
{{ $item->date_begin->format('Y.m.d H:i:s') }}
There's no need to split the value in time and date, just show what you want from the DateTime value using whatever format you want.
If you're not using Eloquent models, then you can manually use Carbon to format your value like so:
{{ Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $item->date_begin)->format('Y.m.d') }}
I have used the PHP solution without Carbon:
Get the database date as you do (with the default format: YYYY-MM-DD HH:MM:SS) and when you print it on your view replace $item->date_begin
to:
date('d-m-Y H:i:s', strtotime($item->date_begin))
After that, when you save it on the database add on the DB update:
date('Y-m-d H:i:s', strtotime($request->date_begin))
protected $casts = [
'inicio' => 'datetime:Y-m-d\TH:i'
,'entrega' => 'datetime:Y-m-d\TH:i'
];
you could use it for the datetime-local field. greed you. like me if work for you
// attributes that should be cast to native types
protected $casts = [
'email_verified_at' => 'datetime'
];
// get formatted datetime string for email_verified_at
public function getEmailVerifiedAttribute()
{
if ($this->email_verified_at) {
$date = Carbon::createFromFormat('Y-m-d H:i:s', $this->email_verified_at, 'UTC');
return $date->setTimezone($this->timezone->name)->isoFormat('LLLL');
} else {
return null;
}
}
as Laravel document way.
I have a JSON file which returns multiple items with different values for concert dates.
So this value returns:
date: "2014-11-27"
and in my HandlebarsJS-template I have:
<p>{{date}}</p>
but I want to display the date like this:
NOV 27
by using HandlebarsJS and yes, I have MomentJS included too.
How can I achieve this?
You could register a Handlebars helper like this:
Handlebars.registerHelper('formatDate', function(dateString) {
return new Handlebars.SafeString(
moment(dateString).format("MMM D").toUpperCase()
);
});
After registering you have to change your template:
<p>{{formatDate date}}</p>
JSFiddle