約 5,341,301 件
https://w.atwiki.jp/dotcom/pages/114.html
日付を整形してStringで返したいの。 SimpleDateFormatクラスを使います。 日付型のフォーマットしてくれます。 使い方。使い方 パターン文字 参考資料 使い方。 java.util.Dateで日付を持つのって推奨していないとのことなので、代わりにjava.util.Calendarを使います。 めずらしく最初から書いたのコピペしてみたわ。 使い方 package dotcom.testtest; import java.util.Calendar; import java.text.SimpleDateFormat; public class SimpleDateFormatTest { private static Calendar cal = Calendar.getInstance(); public static void main(String[] args) { System.out.println("yyyy/mm/dd形式 : " + getFormat1()); } public static String getFormat1() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); return sdf.format(cal.getTime()); } } 結果:今日の日付が2007年3月23日だったら yyyy/mm/dd形式 : 2007/03/23 ってコンソールにでてくるです。 ちなみに cal.getTime() がDate型を返してるです。 newしたときに "yyyy/MM/dd" と指定してるのがパターン文字。 パターン文字 yが年とかそういうの。 これってロケールによって受け取る値が変わっちゃうって。気をつけよう。。。 参考資料 http //www.javaroad.jp/java_date3.htm
https://w.atwiki.jp/dotcom/pages/113.html
Mとm 大文字と小文字です。 Mは「月」 mは「分」 何のことさ?ってSimpleDateFormatクラスのパターン文字です。 フォーマットの定義するときに 2007年03月23日 と出したいとき new SimpleDateFormat("yyyy年mm月dd日"); とするとおかしなことに。 mmは分を表してしまうのでformatするDate型が持つminutes(分)を返しちゃうですよ! 正解は "yyyy年MM月dd日" Mだけ大文字でよろしく。 yもdも小文字だからついMも小文字でやっちゃったですよ ヽ(`д´)ノ!!!
https://w.atwiki.jp/ittec/pages/16.html
【現象】 DateFormat(のサブクラス)をstatic変数で保有している場合、DateFormatの「format」メソッドや「parse」メソッドを使用したときに不正な日付が取得されてしまう。 【例】 public class EditDate() { private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); public Date getDate(String dt) { return sdf.parse(dt); } } 上記のような場合、複数のスレッドからgetDateを呼び出した場合、期待した値とは別の値が取得されてしまう事がある。 【原因】 DateFormatクラスはスレッドセーフではないため、複数のスレッドから同時にアクセスされた場合の結果は保証されていない。 【解決方法】 案1: DateFormatをstatic変数で持たない。 上記例の場合、getDateがstaticメソッドではないため、コンストラクタでDateFormatのインスタンスを生成する。 private SimpleDateFormat sdf = null; public EditDate() { // コンストラクタでDateFormatのインスタンスを生成する sdf = new SimpleDateFormat("yyyy/MM/dd"); } synchronized でスレッドセーフになるのでは? -- nave (2012-07-06 15 37 20) 参考:http //www.ne.jp/asahi/hishidama/home/tech/java/date.html#synchronized_DateFormat -- nave (2012-07-06 15 37 33) 名前 コメント
https://w.atwiki.jp/limixp/pages/20.html
クラス FormatDateWithoutTime import java.util.Calendar; import java.text.SimpleDateFormat; public class FormatDateWithoutTime { private Calendar calendar; private int year; private int month; private int day; public FormatDate() { calendar = Calendar.getInstance(); calendar.setLenient(false); this.year = calendar.get(Calendar.YEAR); this.month = calendar.get(Calendar.MONTH); this.day = calendar.get(Calendar.DAY_OF_MONTH); this.setCalendar(); } public FormatDate(String date) throws NumberFormatException, IllegalArgumentException{ if(date == null){ throw new NumberFormatException(); } if(date.length() != 8){ throw new NumberFormatException(); } Integer.parseInt(date); this.year = Integer.parseInt(date.substring(0,4)); this.month = Integer.parseInt(date.substring(4,6)) - 1; this.day = Integer.parseInt(date.substring(6,8)); calendar = Calendar.getInstance(); this.setCalendar(); calendar.setLenient(false); calendar.getTime(); } public static boolean existDate(String date){ boolean IsYMDDate; if(date != null date.length() == 8){ try{ Integer.parseInt(date); Calendar cal = Calendar.getInstance(); cal.set(Integer.parseInt(date.substring(0,4)), Integer.parseInt(date.substring(4,6)) - 1, Integer.parseInt(date.substring(6,8))); cal.setLenient(false); cal.getTime(); IsYMDDate = true; } catch(Exception e){ IsYMDDate = false; } } else{ IsYMDDate = false; } return IsYMDDate; } public void nextYear(){ try{ this.year = this.year + 1; this.setCalendar(); calendar.getTime(); } catch(Exception e){ this.nextDay(); } } public void prevYear(){ try{ this.year = this.year - 1; this.setCalendar(); calendar.getTime(); } catch(Exception e){ this.prevDay(); } } public void nextMonth(){ try{ this.month = this.month + 1; if(this.month == 12){ this.month = 0; this.nextYear(); } this.setCalendar(); calendar.getTime(); } catch(Exception e){ this.nextDay(); } } public void prevMonth(){ try{ this.month = this.month - 1; if(this.month == -1){ this.month = 11; this.prevYear(); } this.setCalendar(); } catch(Exception e){ this.prevDay(); } } public void nextDay(){ try{ this.day = this.day + 1; this.setCalendar(); calendar.getTime(); } catch(Exception e){ this.day = 1; this.nextMonth(); } } public void prevDay(){ try{ this.day = this.day - 1; if(this.day == 0){ this.day = 31; this.prevMonth(); } this.setCalendar(); calendar.getTime(); } catch(Exception e){ this.prevDay(); } } public String getDate() throws NumberFormatException, IllegalArgumentException{ SimpleDateFormat dateformat = new SimpleDateFormat("yyyyMMdd"); return dateformat.format(calendar.getTime()); } public String getFormatDate(SimpleDateFormat dateformat) throws NumberFormatException, IllegalArgumentException{ return dateformat.format(calendar.getTime()); } private void setCalendar(){ calendar.set(this.year, this.month, this.day); } } トップページ
https://w.atwiki.jp/objcmemo/pages/48.html
- (NSString *)changeDateFormat8To10 (NSString *)strDate { NSString *str = nil; NSDateFormatter *beforeFmt = [[NSDateFormatter alloc] init]; [beforeFmt setDateFormat @"yy/MM/dd"]; NSDate *date = [beforeFmt dateFromString strDate]; NSDateFormatter *afterFmt = [[NSDateFormatter alloc] init]; [afterFmt setDateFormat @"yyyy/MM/dd"]; str = [afterFmt stringFromDate date]; return str; } - (NSString *)changeDateFormat10To8 (NSString *)strDate { NSString *str = nil; NSDateFormatter *beforeFmt = [[NSDateFormatter alloc] init]; [beforeFmt setDateFormat @"yyyy/MM/dd"]; NSDate *date = [beforeFmt dateFromString strDate]; NSDateFormatter *afterFmt = [[NSDateFormatter alloc] init]; [afterFmt setDateFormat @"yy/MM/dd"]; str = [afterFmt stringFromDate date]; return str; }
https://w.atwiki.jp/kome90kome80/pages/17.html
package sample; import java.text.ParseException; import java.text.SimpleDateFormat; public class DateTime { public static void main(String[] args) { //ストリングを結合して日付の型に変換する。 //年 String year = "2014"; //月 String month = "11"; //日 String day = "23"; //年月日 String ymd = year + "/" + month+ "/" + day; //String型からDate型に変換 //パターンの定義 String Date_Pattern = "yyyy/MM/dd"; SimpleDateFormat dateFormat = new SimpleDateFormat(Date_Pattern); //try-catchしないとエラーになった。 try { java.util.Date date = dateFormat.parse(ymd); System.out.print(date); } catch (ParseException e) { System.out.print("catchされました。"); } } }
https://w.atwiki.jp/yoshiumi41/pages/61.html
package part1.greet; import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar; public class date { public static void main(String[] args) throws IsSleepingException {Date now = new Date();DateFormat year = new SimpleDateFormat("yyyy");DateFormat month = new SimpleDateFormat("MM");DateFormat day = new SimpleDateFormat("dd");int yy = Integer.parseInt(year.format(now));int mm = Integer.parseInt(month.format(now)) - 1;int dd = Integer.parseInt(day.format(now)); //おはようございますCalendar c1 = new GregorianCalendar(yy,mm,dd,05,29,59);Calendar c2 = new GregorianCalendar(yy,mm,dd,11,00,00);//こんにちはCalendar c3 = new GregorianCalendar(yy,mm,dd,10,59,59);Calendar c4 = new GregorianCalendar(yy,mm,dd,17,00,00);//こんばんはCalendar c5 = new GregorianCalendar(yy,mm,dd,16,59,59);Calendar c6 = new GregorianCalendar(yy,mm,dd,21,30,00);//おやすみなさいCalendar c7 = new GregorianCalendar(yy,mm,dd,21,29,59);Calendar c8 = new GregorianCalendar(yy,mm,dd+1,00,00,00);Calendar c9 = new GregorianCalendar(yy,mm,dd-1,23,59,59);Calendar c10 = new GregorianCalendar(yy,mm,dd,01,30,00);//就寝中です!//Calendar c11 = new GregorianCalendar(yy,mm,dd,01,29,59);//Calendar c12 = new GregorianCalendar(yy,mm,dd,05,30,00); Calendar c = new GregorianCalendar(yy,mm,dd,01,30,00);Date now1 = c.getTime(); if(now1.after(c1.getTime()) now1.before(c2.getTime())) {System.out.println("おはようございます");} else if(now1.after(c3.getTime()) now1.before(c4.getTime())) {System.out.println("こんにちは");} else if(now1.after(c5.getTime()) now1.before(c6.getTime())) {System.out.println("こんばんは");} else if(now1.after(c7.getTime()) now1.before(c8.getTime()) || now1.after(c9.getTime()) now1.before(c10.getTime()) ) {System.out.println("おやすみなさい");} else {System.out.println("就寝中です!");throw new IsSleepingException();} }}
https://w.atwiki.jp/takeco/pages/5.html
import java.util.Date; import java.text.DateFormat; public class DF{ public static void main(String args[]){ String t,d,td; Date date = new Date(); System.out.println(date); t = DateFormat.getTimeInstance().format(date); System.out.println(t); d = DateFormat.getDateInstance().format(date); System.out.println(d); td = DateFormat.getDateTimeInstance().format(date); System.out.println(td); //--------------------- // case getTimeInstance //--------------------- System.out.println("case getTimeInstance"); try{ date = DateFormat.getTimeInstance().parse(t); System.out.println("T t " + date); }catch(Exception e){} try{ date = DateFormat.getTimeInstance().parse(d); System.out.println("T d " + date); }catch(Exception e){} try{ date = DateFormat.getTimeInstance().parse(td); System.out.println("T td " + date); }catch(Exception e){} try{ date = DateFormat.getTimeInstance().parse(date.toString()); System.out.println("T " + date); }catch(Exception e){} //--------------------- // case getDateInstance //--------------------- System.out.println("case getDateInstance"); try{ date = DateFormat.getDateInstance().parse(t); System.out.println("D t " + date); }catch(Exception e){} try{ date = DateFormat.getDateInstance().parse(d); System.out.println("D d " + date); }catch(Exception e){} try{ date = DateFormat.getDateInstance().parse(td); System.out.println("D td " + date); }catch(Exception e){} try{ date = DateFormat.getDateInstance().parse(date.toString()); System.out.println("D " + date); }catch(Exception e){} //--------------------- // case getDateTimeInstance //--------------------- System.out.println("case getDateTimeInstance"); try{ date = DateFormat.getDateTimeInstance().parse(t); System.out.println("DT t " + date); }catch(Exception e){}try{ date = DateFormat.getDateTimeInstance().parse(d); System.out.println("DT d " + date); }catch(Exception e){}try{ date = DateFormat.getDateTimeInstance().parse(td); System.out.println("DT td " + date); }catch(Exception e){}try{ date = DateFormat.getDateTimeInstance().parse(date.toString()); System.out.println("DT " + date); }catch(Exception e){} } }
https://w.atwiki.jp/javamock/pages/30.html
Date Javaにおいて java.util.Dateクラスは日付・時刻を扱うクラスです。 精度はミリ秒です。 Dateクラスのコンストラクタ Date() は現在の日時を保持したDateオブジェクトを生成します。 Dateクラスのコンストラクタ Date(long date) は指定されたミリ秒の値を使って Date オブジェクトを構築します。 また、Dateクラスのメソッドは以下のようなものがあります。※他にもあります setTime(long time) は1970/01/01 00 00 00 GMT からtimeミリ秒の時点を表すように設定します。 toString() はDateオブジェクトを文字列型に変換します。 after(Date when) はこの日付が、指定された日付より後にあるかどうかを判定します。 before(Date when) はこの日付が、指定された日付より前にあるかどうかを判定します。 Date 使用例 1 DateSample.java class DateSample { public static void main(String[] args) { // 現在日時 java.util.Date dateObject1 = new java.util.Date(); System.out.println("dateObject1 " + dateObject1); // 1970/01/01 00 00 00.000 java.util.Date dateObject2 = new java.util.Date(0); System.out.println("dateObject2 " + dateObject2); // 1970/01/01 00 00 00.000 から10000000000000ミリ秒経過時間 java.util.Date dateObject3 = new java.util.Date(10000000000000L); System.out.println("dateObject3 " + dateObject3); // setTime(long time) は指定されたミリ秒の値を使って、既存の Date オブジェクトを設定します。 java.util.Date dateObject4 = new java.util.Date(); dateObject4.setTime(20000000000000L); System.out.println("dateObject4 " + dateObject4); // toString() Dateオブジェクトを文字列型に変換します。 System.out.println(dateObject3.toString() + "\t" + dateObject4.toString()); // after(Date when),before(Date when)で日付の比較を行います。 System.out.println("dateObject1.after(dateObject2) " + dateObject1.after(dateObject2)); System.out.println("dateObject2.after(dateObject1) " + dateObject2.after(dateObject1)); System.out.println("dateObject1.before(dateObject2) " + dateObject1.before(dateObject2)); System.out.println("dateObject2.before(dateObject1) " + dateObject2.before(dateObject1)); } } 実行結果 C \java javac DateSample.java C \java java DateSample dateObject1 Tue Mar 03 22 59 48 JST 2009 dateObject2 Thu Jan 01 09 00 00 JST 1970 dateObject3 Sun Nov 21 02 46 40 JST 2286 dateObject4 Tue Oct 11 20 33 20 JST 2603 Sun Nov 21 02 46 40 JST 2286 Tue Oct 11 20 33 20 JST 2603 dateObject1.after(dateObject2) true dateObject2.after(dateObject1) false dateObject1.before(dateObject2) false dateObject2.before(dateObject1) true また、「Thu Jan 01 09 00 00 JST 1970」のような表記ではなく他のフォーマットにしたい場合には、 java.text.DateFormatやjava.text.SimpleDateFormatなどDate型のフォーマットを行えるクラスがあります。
https://w.atwiki.jp/fwsimple/pages/108.html
TeamSpeak3ってナニ? 低負荷で使用できるボイス&テキストチャットツール、通称TS3です。 Skypeに比べ、負荷がかからず人数制限もなく なによりも参加者から招待を受けなくても自由に出入りが出来るのが魅力です。 またアリーナやIDなどで複数の会話が同時進行してしまうような場合も サブチャンネル(専用の小部屋のようなもの)を作って分かれて話すことが出来ます。 ボイスチャットしなきゃダメ? ボイスチャットをしない聞き専でももちろんうぇるかむです! 声が聞こえていればIDなどでの動きも反応しやすくなりますし、何かと便利です。 が、もちろんそういうものに抵抗のある人がいることも理解していますし、強制ではありません。 個人的には色んな人としゃべってみたいけどね! マイク必要? 聞き専であれば必要ありません。 スピーカーなりヘッドフォンなり、音が聞ける環境なら大丈夫です。 お金かかる? もちろん無料です。 ですが、一般の方が公開しているサーバーを間借りしているため 15日以上アクセスがないとチャンネルを没収されてしまいます。 それも含めて、ぜひ積極的な参加をお願いします。 TeamSpeak3の導入の仕方 1.公式サイトからクライアントをDLします ほとんどの人はWindowsかな? Vista/XP/7で32bitの人はClient 32-bit 3.0.5 62bitの人はClient 62-bit 3.0.5 どっちかわからないって人はスタート→コントロールパネル→システムで確認できます。 DLしたらもちろん解凍してね。 2.必要であれば日本語化パッチを当てます(英語でよければやらなくていいよ) このサイトから最新版の日本語化パッチをDLし、実行します。 実行するとモジュールが出てくるので、↑のクライアントを入れた場所を指定すれば それだけで日本語化されます。 3.TS3サーバーに接続します 左上の[接続]メニューから[接続]を選択し、 サーバーアドレス:2nd.3peace.info ニックネーム:FWでの名前 パスワード:空欄 を入力して接続します。 接続後、リストから[simple Guild TS3 Chaannel]を検索し (Permanent N-Zグループの中にはいっています) クリック→パスワード「simplets3」を入力で入室できます。 「こねくてっど」とおねーさんが言ったら成功。 音量調整の仕方 TS3では一定以上の音をマイクが拾った場合のみ マイクがつながるというシステムがデフォルトになっています。 これにより生活音など聞こえなくていい雑音はカットされ しゃべっているときのみ音が入るようになっている便利仕様なのですが この"一定以上"によっては喋る声までカットされ会話がぶつぶつ途切れてしまったり 逆に常に雑音を拾ってマイクがつながり続けてしまう可能性もあります。 この場合には「設定」メニューの「オプション」から「録音」タブを選択し 「テストを開始」ボタンを押して、バーのポインタを動かすことで 「一定以上」の規準を調整できます。 緑のラインが触れるか触れないかのところにポインタがあるのが良いんじゃないかな?