Skip to content

Instantly share code, notes, and snippets.

@chriskacerguis
Last active August 29, 2015 14:26
Show Gist options
  • Save chriskacerguis/7e5f91bbb48bbe48bf7f to your computer and use it in GitHub Desktop.
Save chriskacerguis/7e5f91bbb48bbe48bf7f to your computer and use it in GitHub Desktop.
How to convert an HeathKit NSDate time format to a Unix Timestamp for PHP
<?php
// This will convert a iOS HealthKit Data Export startDate or endDate (NSDate format)
// into a DateTime Object for use in PHP
// Written by Chris Kacerguis
$nsdate = '20150802105200-0500';
$format = 'YmdHis-O';
$objDateTime = DateTime::createFromFormat('YmdHis', (int) $time);
$human_readable = $objDateTime->format('F d, Y h:ia');
$unix_timestamp = $objDateTime->format('U');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment