WIKI使用導(dǎo)航
站長(zhǎng)百科導(dǎo)航
站長(zhǎng)專題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢
- 虛擬主機(jī)
- cPanel
- 網(wǎng)址導(dǎo)航專題
- 云計(jì)算
- 微博營(yíng)銷
- 虛擬主機(jī)管理系統(tǒng)
- 開放平臺(tái)
- WIKI程序與應(yīng)用
- 美國(guó)十大主機(jī)
Drupal:有起始和結(jié)束時(shí)間,來計(jì)算持續(xù)時(shí)間
來自站長(zhǎng)百科
此例使用KarenS的日期模塊來創(chuàng)建兩個(gè)日期字段field_start_time和field_end_time,它們記錄小時(shí)數(shù)和分鐘數(shù)。接著我們創(chuàng)建一個(gè)計(jì)算型字段來定義持續(xù)時(shí)間--小時(shí)數(shù)--為一類小數(shù)數(shù)字,比如1.5就是1小時(shí)30分鐘。
計(jì)算型字段設(shè)定:
- Computed Code,計(jì)算代碼:
$start_date = date_make_date($node->field_start_time[0]['value']); $start = $start_date->db->parts; $end_date = date_make_date($node->field_end_time[0]['value']); $end = $end_date->db->parts; $start_decimal = $start['hours'] + ($start['minutes'] / 60); $end_decimal = $end['hours'] + ($end['minutes'] / 60); $node_field[0]['value'] = $end_decimal - $start_decimal;
- 檢查 'Display this field'
- Display Format,顯示格式:$display = $node_field_item['value'] . " hours";
- 檢查 'Store using the database settings below'
- Data Type,數(shù)據(jù)類型: float(浮點(diǎn))
- Data Length,數(shù)據(jù)長(zhǎng)度: 3,2
- 檢查 'Sortable'