Column Format – Time!
Good Afternoon
I’m trying to format a DateTime field with a bit of verve. I got JSON from GitHub but I need to modify as I want to include the time. – The only example that includes what I’m looking for is this:
https://github.com/pnp/List-Formatting/tree/master/column-samples/generic-world-time
But I can’t get it quite to work and I don’t understand why.
This is what I’m aiming for but the time represented is 21 June – 2:30 pm! I’m 14 hours out (Regional Settings are Australia, UTC + 10)
As the original code comes from something that does a time conversion, I thought to take out the bit that adds the conversion factor. I have tried removing “+Number([$UTC]” (and why isn’t it screaming at me anyway for including a reference to a non-existing field?), adding 0, multiplying by one …
“elmType”: “div”,
“children”: [
{
“elmType”: “span”,
“txtContent”: “=padStart(toString(floor(((Number(@currentField)+Number([$UTC])*3600000)%86400000)/3600000)),2,’0′)”
},
{
“elmType”: “span”,
“txtContent”: “:”
},
{
“elmType”: “span”,
“txtContent”: “=padStart(toString(floor(((Number(@currentField)+Number([$UTC])*3600000)%86400000)%3600000/60000)),2,’0′)”
}
]
They all result in something like this:
It’s all a foreign language to me but I’ve worked out:
padStart pads the string at the beginning with 0 to a length of 2 – won’t actually need that for the hour, happy with 1:30 pmNumber I’m guessing turns the date time string into a number which we can then manipulatefloor does some rounding, not sure why that’s neededtoString turns it back into a string for display, I imagine
But I don’t understand why it would need the UTC calculation. And I think it’s the UTC calculation that messes with my times.
If anybody understands this or can point me to some documentation that will help me understand, I would appreciate it.
Thanks
Christine
Good Afternoon I’m trying to format a DateTime field with a bit of verve. I got JSON from GitHub but I need to modify as I want to include the time. – The only example that includes what I’m looking for is this:https://github.com/pnp/List-Formatting/tree/master/column-samples/generic-world-timeBut I can’t get it quite to work and I don’t understand why. This is what I’m aiming for but the time represented is 21 June – 2:30 pm! I’m 14 hours out (Regional Settings are Australia, UTC + 10)As the original code comes from something that does a time conversion, I thought to take out the bit that adds the conversion factor. I have tried removing “+Number([$UTC]” (and why isn’t it screaming at me anyway for including a reference to a non-existing field?), adding 0, multiplying by one … “elmType”: “div”,
“children”: [
{
“elmType”: “span”,
“txtContent”: “=padStart(toString(floor(((Number(@currentField)+Number([$UTC])*3600000)%86400000)/3600000)),2,’0′)”
},
{
“elmType”: “span”,
“txtContent”: “:”
},
{
“elmType”: “span”,
“txtContent”: “=padStart(toString(floor(((Number(@currentField)+Number([$UTC])*3600000)%86400000)%3600000/60000)),2,’0′)”
}
] They all result in something like this:It’s all a foreign language to me but I’ve worked out:padStart pads the string at the beginning with 0 to a length of 2 – won’t actually need that for the hour, happy with 1:30 pmNumber I’m guessing turns the date time string into a number which we can then manipulatefloor does some rounding, not sure why that’s neededtoString turns it back into a string for display, I imagineBut I don’t understand why it would need the UTC calculation. And I think it’s the UTC calculation that messes with my times. If anybody understands this or can point me to some documentation that will help me understand, I would appreciate it.ThanksChristine Read More