LoginSignup
0
0

More than 3 years have passed since last update.

salesforce(今更その2)ListとDateTimeの便利技

Last updated at Posted at 2019-09-10

Listのサイズは決められる

Listってあらかじめサイズを決めておいてなんばん目に格納するかを決められるんですね。
1年やってて初めて知った。。。

sample
String[] sampleList = new String[10];
system.debug(sampleList);
system.debug(sampleList.size());

スクリーンショット 2019-09-10 20.20.31.png

nullが入るんすね。
Integerとかでも同じ形になりました。

ここに値を代入していきます。

sample
sampleList[0] = '朝起きる';
sampleList[5] = '歯を磨く';
sampleList[9] = '家を出る';

スクリーンショット 2019-09-10 20.27.07.png

ちゃんと指定した箇所に代入されてますね。
うまく使えばリスト並び順を指定したリストを作るのに役立ちそうです。

DateTimeで曜日をとれる!!

Date型では曜日を取ることはできないんですが、DateTime型では曜日を取得することができるみたいです。

sample
DateTime sampleDate = datetime.newInstance(2019, 09, 10);
system.debug(sampleDate.format('EEE'));
system.debug(sampleDate.format('EEEEE'));

スクリーンショット 2019-09-10 20.32.14.png

format()の中に'EEE'もしくは'EEEEE'を入力します。
'EEE'は略称の曜日が'EEEEE'では正式な形で出力されます。

土日の判定とかこれでできますね。

今更かもですが初めて知ったことばっかりなので書きました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0