Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/users/1/juny/web/hidef/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/users/1/juny/web/hidef/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

NSDateを5分刻み・15分刻みで丸める

公開日: : 最終更新日:2014/08/01 iPhone App 開発, Objective-C


Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/users/1/juny/web/hidef/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

NsDateを初期値としてUIDatePicker等に設定する場合、日付の丸め処理が必要になるのでメモ。

NsDateを5分間隔で丸める処理

+ (NSDate *)round5Minites:(NSDate *)date
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setLocale:[NSLocale systemLocale]];
    [formatter setDateFormat:@"m"];
    int ref = [[formatter stringFromDate:date] intValue];
    if (ref % 5 != 0)
    {
        float def = round(ref * 0.1f) * 10;
        if(def < ref) def += 5;
        date = [date dateByAddingTimeInterval:60 * (def - ref)];
    }
    return date;
}

NsDateを15分間隔で丸める処理

+ (NSDate *)round15Minites:(NSDate *)date
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setLocale:[NSLocale systemLocale]];
    [formatter setDateFormat:@"mm"];
    int minutes = [[formatter stringFromDate:date] intValue];
    [formatter setDateFormat:@"ss"];
    int seconds = [[formatter stringFromDate:date] intValue];
    int remain = minutes % 15;
    return [date dateByAddingTimeInterval:-(60 * remain) - seconds];
}

以上。

ad

関連記事

[Swift] optional値の設定(??)

optional値がnilの時 プロジェクトでのテンプレートを選択した時にソースコードが自動生成さ

記事を読む

Xcode5のstoryboard内でUIKeyCommandエラーの対処法

既存のプロジェクトからstoryboardにあるオブジェクトをコピペして、新規プロジェクトに貼付けた

記事を読む

[Swift] Asset Catalogについて

XCode5から追加されたAsset Catalog。 いままで標準のImages.xcasset

記事を読む

[Swift] CoreDataを使ってみる

SwiftでCoreData 今回はSwiftでCoreDataを使ってみます。 Xcodeプロ

記事を読む

備忘録的メモ

Xcode5にアップデートして、とりあえずアプリを走らせてみたらナビゲーションバーがかぶってる・・・

記事を読む

[Objective-C] 文字列操作の便利Tips

Tipsいろいろ 先日の投稿 共通関数をまとめたクラスを作ろう!の流れで、文字列を操作するときに便

記事を読む

no image

小さなことからコツコツと

これまでHTMLとCSSだけで生きてきただけあって、プログラム言語がいまいちわからない。 Mo

記事を読む

[Swift] CoreDataで検索したデータを削除する

CoreDataの検索と削除 前の投稿  CoreDataを使ってみる をふまえて今度は検索&削除

記事を読む

[Swift] プロパティリスト(plist)を使ってCoreDataで一括登録する

プロパティリストを使う 初期データやあらかじめ用意したデータを一括登録したい場合、プロパティリスト

記事を読む

[Swift] 定数クラスをつくってみる

Objective-cの場合 今回は共通にする定数をまとめるクラスを作ってみます。 まずはO

記事を読む

ad

Message

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

ad

[PHP] curl転送してみる(googleに)

curlでgoogle画像検索APIにアクセスしてみます。 cu

[PHP] PDOでMySQLの接続確認をする

PDO PHPでMySQLに接続する際には、mysql_connec

[PHP] ランダムな英数字を生成する

便利系メソッド 今回はPHPでランダムな英数字を作成してみます。

[Swift] プロパティリスト(plist)の値を取得

plistからデータを取得してみます。 こちらのエントリーも参考にし

[Swift] Asset Catalogについて

XCode5から追加されたAsset Catalog。 いままで標準

→もっと見る

  • 1978年の七夕生まれ。 25才でweb業界の門を叩き、28才でフリーランスに。 現在は、フリーランスでマークアップ中心に、wordpressのカスタマイズやデザインをしております。 また、iPhoneアプリの開発もしております。

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/users/1/juny/web/hidef/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524
PAGE TOP ↑

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/users/1/juny/web/hidef/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524