Date manipulation: Difference between revisions
Content added Content deleted
(FutureBasic solution added) |
|||
Line 1,308: | Line 1,308: | ||
{{FormulaeEntry|page=https://formulae.org/?timeZone=America%2FNew_York&script=examples/Date_manipulation}} |
{{FormulaeEntry|page=https://formulae.org/?timeZone=America%2FNew_York&script=examples/Date_manipulation}} |
||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic"> |
|||
void local fn DoIt |
|||
CFStringRef monthString, zoneString, ampmString |
|||
long month, day, year, hour, minute |
|||
CFStringRef dateString = @"March 7 2009 7:30pm EST" |
|||
DateFormatterRef df = fn DateFormatterInit |
|||
DateFormatterSetDateStyle( df, NSDateFormatterMediumStyle ) |
|||
DateFormatterSetTimeStyle( df, NSDateFormatterMediumStyle ) |
|||
DateFormatterSetDateFormat( df, @"MMMM d YYYY h:ma" ) |
|||
CFArrayRef months = fn DateFormatterMonthSymbols( df ) |
|||
CFCharacterSetRef spaceSet = fn CharacterSetWhitespaceSet |
|||
ScannerRef scanner = fn ScannerWithString( dateString ) |
|||
ScannerSetCharactersToBeSkipped( scanner, fn CharacterSetWithCharactersInString(@": ") ) |
|||
fn ScannerScanUpToCharactersFromSet( scanner, spaceSet, @monthString ) |
|||
fn ScannerScanInteger( scanner, @day ) |
|||
fn ScannerScanInteger( scanner, @year ) |
|||
fn ScannerScanInteger( scanner, @hour ) |
|||
fn ScannerScanInteger( scanner, @minute ) |
|||
fn ScannerScanUpToCharactersFromSet( scanner, spaceSet, @ampmString ) |
|||
fn ScannerScanUpToCharactersFromSet( scanner, spaceSet, @zoneString ) |
|||
month = fn ArrayIndexOfObject( months, monthString ) + 1 |
|||
if ( fn StringIsEqual( ampmString, @"pm" ) ) then hour += 12 |
|||
DateComponentsRef comps = fn DateComponentsInit |
|||
DateComponentsSetMonth( comps, month ) |
|||
DateComponentsSetDay( comps, day ) |
|||
DateComponentsSetYear( comps, year ) |
|||
DateComponentsSetHour( comps, hour + 12 ) |
|||
DateComponentsSetMinute( comps, minute ) |
|||
CFDateRef dt = fn CalendarDateFromComponents( fn CalendarCurrent, comps ) |
|||
CFStringRef string = fn DateFormatterStringFromDate( df, dt ) |
|||
string = fn StringByAppendingFormat( string, @" %@", zoneString ) |
|||
print string |
|||
end fn |
|||
fn DoIt |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
<pre> |
|||
March 8 2009 7:30am EST |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |