covert EpochTime to Datetime and covert Datetime to EpochTime
/// <summary>
/// Converts the given date value to epoch time.
/// </summary>
public static long ToEpochTime(this DateTime dateTime)
{
var date = dateTime.ToUniversalTime();
var ticks = date.Ticks - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).Ticks;
var ts = ticks / TimeSpan.TicksPerSecond;
return ts;
}
/// <summary>
/// Converts the given date value to epoch time.
/// </summary>
public static long ToEpochTime(this DateTimeOffset dateTime)
{
var date = dateTime.ToUniversalTime();
var ticks = date.Ticks - new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero).Ticks;
var ts = ticks / TimeSpan.TicksPerSecond;
return ts;
}
/// <summary>
/// Converts the given epoch time to a <see cref="DateTime"/> with <see cref="DateTimeKind.Utc"/> kind.
/// </summary>
public static DateTime ToDateTimeFromEpoch(this long intDate)
{
var timeInTicks = intDate * TimeSpan.TicksPerSecond;
return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddTicks(timeInTicks);
}
/// <summary>
/// Converts the given epoch time to a UTC <see cref="DateTimeOffset"/>.
/// </summary>
public static DateTimeOffset ToDateTimeOffsetFromEpoch(this long intDate)
{
var timeInTicks = intDate * TimeSpan.TicksPerSecond;
return new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero).AddTicks(timeInTicks);
}
This example shows how to load a JSON feed into a ScenGraph RowList in Roku. It's not a complete application. This code started life as Simple_Grid_with_Details_and_Video, available here: https://blog.roku.com/developer/2016/03/03/scenegraph-tutorial/
The json_parser.brs file has the brightscript code to load the feed data (represented by the contents of data.json).
The data is then translated into an array of MediaItems. MediaItem is an extended ContentNode.
Then the data is structured to load into a RowList, which is represented in GridScreen.xml.
{
"$xmlns": {
"pl1": "http://access.auth.theplatform.com/data/Account/2295898951",
"nbcu": "http://xml.nbcuni.com/media/field"
},
"startIndex": 1,
"itemsPerPage": 3,
"entryCount": 3,
"title": "PROD Feed for Video Assets",
"description": "PROD Feed for Video Assets",
"entries": [
{
"id": "http://data.media.theplatform.com/media/data/Media/939146307771",
"guid": "3515752",
"updated": 1494453617000,
"title": "Queen of the South - There’s A New Queen In Town",
"description": "Queen of the South premieres Thursday, June 8 at 10/9c.",
"added": 1494285069000,
"availableDate": 1494453600000,
"expirationDate": 1497002400000,
"categories": [
{
"name": "Series/Queen of the South",
"scheme": "",
"label": ""
}
],
"copyright": "",
"copyrightUrl": "",
"keywords": "Queen of the South,Alice Braga,Adrana Barraza,Hemky Madera,James Martinez,Joaquim de Almeida",
"ratings": [
{
"scheme": "urn:mpaa",
"rating": "nr",
"subRatings": [
]
}
],
"countries": [
"GU",
"MP",
"PR",
"US",
"VI"
],
"excludeCountries": false,
"content": [
{
"duration": 30.030,
"format": "MPEG4",
"height": 240,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 416
},
{
"duration": 30.030,
"format": "MPEG4",
"height": 544,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 960
},
{
"duration": 30.000,
"format": "MPEG4",
"height": 720,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 1280
},
{
"duration": 30.000,
"format": "MPEG4",
"height": 540,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 960
},
{
"duration": 30.000,
"format": "MPEG4",
"height": 1080,
"isDefault": true,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 1920
},
{
"duration": 30.000,
"format": "MPEG4",
"height": 360,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 640
},
{
"duration": 30.000,
"format": "MPEG4",
"height": 234,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 416
},
{
"duration": 0.000,
"format": "TCM",
"height": 0,
"isDefault": false,
"language": "",
"url": "http://link.theplatform.com/...",
"width": 0
}
],
"thumbnails": [
{
"duration": 0.000,
"format": "JPEG",
"height": 1080,
"isDefault": false,
"language": "",
"url": "http://tve-static-usanetwork.nbcuni.com/prod/image/664/731/170508_3515752_Queen_of_the_South___Action_Packed_anvver_2.jpg",
"width": 1920
}
],
"pubDate": 1494283080000,
"defaultThumbnailUrl": "http://tve-static-usanetwork.nbcuni.com/prod/image/664/731/170508_3515752_Queen_of_the_South___Action_Packed_anvver_2_800x450_939405379534.jpg",
"provider": "USA",
"pl1$dayPart": "Primetime",
"pl1$entitlement": "free",
"pl1$event": "",
"pl1$externalAdvertiserId": "USA_ANV_3515752",
"pl1$fullEpisode": false,
"pl1$promo": false,
"pl1$seasonNumber": 2,
"pl1$shortDescription": "Queen of the South premieres Thursday, June 8 at 10/9c.",
"pl1$shortTitle": "Queen of the South - There’s A New Queen In Town",
"nbcu$advertisingGenre": "Drama",
"nbcu$programmingType": "Undefined"
},
{
"id": "http://data.media.theplatform.com/media/data/Media/939128899982",
"guid": "3515747",
"updated": 1494324030000,
"title": "Queen of the South - All The Way Up",
"description": "Catch the premiere of Queen of the South Thursday, June 8 at 10/9c.",
"added": 1494283878000,
"availableDate": 1494324000000,
"expirationDate": 1497002400000,
"categories": [
{
"name": "Series/Queen of the South",
"scheme": "",
"label": ""
}
],
"copyright": "",
"copyrightUrl": "",
"keywords": "Queen of the South,Alice Braga,Adrana Barraza,Hemky Madera,James Martinez,Joaquim de Almeida",
"ratings": [
{
"scheme": "urn:mpaa",
"rating": "nr",
"subRatings": [
]
}
],
"countries": [
"GU",
"MP",
"PR",
"US",
"VI"
],
"excludeCountries": false,
"content": [
{
"duration": 60.000,
"format": "MPEG4",
"height": 360,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 640
},
{
"duration": 60.061,
"format": "MPEG4",
"height": 544,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 960
},
{
"duration": 60.000,
"format": "MPEG4",
"height": 234,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 416
},
{
"duration": 60.061,
"format": "MPEG4",
"height": 240,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 416
},
{
"duration": 60.000,
"format": "MPEG4",
"height": 720,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 1280
},
{
"duration": 60.000,
"format": "MPEG4",
"height": 540,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 960
},
{
"duration": 60.000,
"format": "MPEG4",
"height": 1080,
"isDefault": true,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 1920
},
{
"duration": 0.000,
"format": "TCM",
"height": 0,
"isDefault": false,
"language": "",
"url": "http://link.theplatform.com/...",
"width": 0
}
],
"thumbnails": [
{
"duration": 0.000,
"format": "JPEG",
"height": 1080,
"isDefault": false,
"language": "",
"url": "http://tve-static-usanetwork.nbcuni.com/prod/image/648/115/170508_3515747_Queen_of_the_South___All_The_Way_Up.jpg",
"width": 1920
}
],
"pubDate": 1494282540000,
"defaultThumbnailUrl": "http://tve-static-usanetwork.nbcuni.com/prod/image/648/115/170508_3515747_Queen_of_the_South___All_The_Way_Up_800x450_939133507784.jpg",
"provider": "USA",
"pl1$dayPart": "Primetime",
"pl1$entitlement": "free",
"pl1$event": "",
"pl1$externalAdvertiserId": "USA_ANV_3515747",
"pl1$fullEpisode": false,
"pl1$promo": false,
"pl1$seasonNumber": 2,
"pl1$shortDescription": "Catch the premiere of Queen of the South Thursday, June 8 at 10/9c.",
"pl1$shortTitle": "Queen of the South - All The Way Up",
"nbcu$advertisingGenre": "Drama",
"nbcu$programmingType": "Undefined"
},
{
"id": "http://data.media.theplatform.com/media/data/Media/914045507807",
"guid": "3496379",
"updated": 1494151208000,
"title": "Big Star Little Star Interview: Penn Jillette, Brooke Burke, Harold Perrineau",
"description": "Meet the celebrity contestants of the hilarious new game show, BIG STAR LITTLE STAR. Check out more exclusive BIG STAR LITTLE STAR videos, galleries and more at usanetwork.com.",
"added": 1491347776000,
"availableDate": 1494151200000,
"expirationDate": 1499853600000,
"categories": [
{
"name": "Series/Big Star Little Star",
"scheme": "",
"label": ""
}
],
"copyright": "",
"copyrightUrl": "",
"keywords": "Big Star Little Star,Cat Deeley,Corin Nelson,David George,Brian Zagorsk",
"ratings": [
{
"scheme": "urn:v-chip",
"rating": "tv-pg",
"subRatings": [
]
}
],
"countries": [
],
"excludeCountries": true,
"content": [
{
"duration": 63.000,
"format": "MPEG4",
"height": 1080,
"isDefault": true,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 1920
},
{
"duration": 63.000,
"format": "MPEG4",
"height": 720,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 1280
},
{
"duration": 63.000,
"format": "MPEG4",
"height": 360,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 640
},
{
"duration": 63.364,
"format": "MPEG4",
"height": 240,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 416
},
{
"duration": 63.000,
"format": "MPEG4",
"height": 540,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 960
},
{
"duration": 0.000,
"format": "TCM",
"height": 0,
"isDefault": false,
"language": "",
"url": "http://link.theplatform.com/...",
"width": 0
},
{
"duration": 63.000,
"format": "MPEG4",
"height": 234,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 416
},
{
"duration": 63.364,
"format": "MPEG4",
"height": 544,
"isDefault": false,
"language": "en",
"url": "http://link.theplatform.com/...",
"width": 960
}
],
"thumbnails": [
{
"duration": 0.000,
"format": "JPEG",
"height": 1080,
"isDefault": false,
"language": "",
"url": "http://tve-static-usanetwork.nbcuni.com/prod/image/278/743/170404_3496379_Big_Star_Little_Star_Interview___Penn_Jillet.jpg",
"width": 1920
}
],
"pubDate": 1491341820000,
"defaultThumbnailUrl": "http://tve-static-usanetwork.nbcuni.com/prod/image/278/743/170404_3496379_Big_Star_Little_Star_Interview___Penn_Jillet_800x450_914051139503.jpg",
"provider": "USA",
"pl1$dayPart": "Primetime",
"pl1$entitlement": "free",
"pl1$event": "",
"pl1$externalAdvertiserId": "USA_ANV_3496379",
"pl1$fullEpisode": false,
"pl1$promo": false,
"pl1$seasonNumber": 1,
"pl1$shortDescription": "Meet the celebrity contestants of the hilarious new game show, BIG STAR LITTLE STAR. Check out more exclusive BIG STAR LITTLE STAR videos, galleries and more at usanetwork.com.",
"pl1$shortTitle": "Big Star Little Star Interview: Penn Jillette, Brooke Burke, Harold Perrineau",
"nbcu$advertisingGenre": "Reality and Game Show",
"nbcu$programmingType": "Behind the Scenes"
}
]
}
parse_json.brs
sub loadContent()
shortFormRow = GetShortForm()
list = [
{
TITLE : "Short Form"
ContentList : shortFormRow
}
]
m.contentselection = m.top.findNode("GridScreen")
m.contentselection.content = ParseContent(list)
end sub
Function GetShortForm()
url = CreateObject("roUrlTransfer")
url.SetUrl("http://yourcontentprovider.com/data.json")
rsp = url.GetToString()
response = parseJSON(rsp)
result = parseFeed(response)
return result
End Function
function parseFeed(feed)
result = []
regex = CreateObject("roRegex", "/", "i")
for each item in feed.entries
asset = {}
asset.HDPosterUrl = item.defaultThumbnailUrl
asset.hdBackgroundImageUrl = item.defaultThumbnailUrl
asset.streamFormat = "hls"
asset.Categories=[]
asset.filmstrip= item.filmstrip
asset.thumbnail = item.defaultThumbnailUrl
asset.title = item.title
asset.description = item.description
asset.releasedate = item.added
asset.mpxmediaguid = item.guid
asset.entitlement = item["pl1$entitlement"]
asset.externaladvertiserid =item["pl1$externalAdvertiserId"]
asset.duration = item.content[0].duration
if item.ownerId <> invalid
asset.mpxAccountId = regex.Split(item.ownerId).peek()
else
asset.mpxAccountId = "2304992029"
end if
if item.categories <> invalid AND item.categories[0] <> invalid
asset.category=item.categories[0].name
end if
mediaType = "VOD Clip"
if item["pl1$fullEpisode"] = true OR item["nbcu$fullEpisode"] = true
mediaType = "VOD Episode"
end if
asset.trackingData = {}
asset.trackingdata["tve.videoprogram"] = item.title
asset.trackingdata["tve.videocontent"] = mediaType
asset.TrackingData["tve.length"] = item.content[0].duration
asset.TrackingData["tve.season"] = "999"
asset.TrackingData["tve.epnumber"] = "888"
asset.TrackingData["tve.airdate"] = "2001-04-01"
asset.stream = {url:""}
result.push(asset)
end for
return result
end function
Function ParseContent(list As Object)
RowItems = createObject("RoSGNode","ContentNode")
for each rowAA in list
row = createObject("RoSGNode","ContentNode")
row.Title = rowAA.Title
for each itemAA in rowAA.ContentList
item = createObject("RoSGNode","MediaItem")
' We don't use item.setFields(itemAA) as doesn't cast streamFormat to proper value
for each key in itemAA
item[key] = itemAA[key]
end for
row.appendChild(item)
end for
RowItems.appendChild(row)
end for
return RowItems
End Function
https://stackoverflow.com/questions/36092553/how-to-format-a-carbon-date-to-get-the-full-month
Y = full Year
F = Month (label)
d = 2 digit day number
{{ \Carbon\Carbon::parse($new->uploaded_date)->format('Y F d') }}
will print 2018 February 22
change the order of format('Y F d') as needed
text 从#MassGIS #MAD #masteraddresslist geodatabase#ogr2ogr导出#address表
# This is a guess the number game
import random
secret_number = random.randint(1, 20)
print('I am thionking of a number between 1 and 20.')
# Ask the player to guess 6 times.
for guesses_taken in range(1, 7):
print('Take a guess.')
guess = int(input())
if guess < secret_number:
print('Your guess is too low.')
elif guess > secret_number:
print('Your guess is too high.')
else:
break #This is condition is correct guess!
if guess == secret_number:
print('Good job! You guessed my number in ' + str(guesses_taken) + ' guesses!')