Salesforceアプリケーションで、ユーザーに日付/時刻の値を入力させたいのですが、時刻の部分はオプションです。これを達成する方法はありますか?ありがとう。
4514 次
3 に答える
2
解決策として、カスタム オブジェクト フィールド タイプの DateTime 値を使用するのではなく、VF コントローラー レベルで個別の Date 値と Time 値を保持し、それらの値を構成して DateTime を作成します。
Apex コードは次のとおりです。
// Compos DateTime with Date & Time values
this.jobOccurrence.Date_Time_Sampled__c = DateTime.parse(this.dateSampled.trim() + ' ' + this.timeSampled.trim());
VisualForce コードは次のとおりです。
<apex:page>
<!-- Style sheet for timepicker -->
<link rel="stylesheet" media="all" type="text/css" href="{!URLFOR($Resource.jquery_ui_custom)}" />
<style>
#ui-datepicker-div, .ui-datepicker{ font-size: 70%; }
.ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
.ui-timepicker-div dl { text-align: left; }
.ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }
.ui-timepicker-div dl dd { margin: 0 10px 10px 65px; }
.ui-timepicker-div td { font-size: 90%; }
.ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0;
</style>
<!-- javascript for timepicker -->
<script type="text/javascript" src="{!URLFOR($Resource.jquery)}"></script>
<script type="text/javascript" src="{!URLFOR($Resource.jquery_ui_custom_min)}"></script>
<script type="text/javascript" src="{!URLFOR($Resource.jquery_ui_timepicker_addon)}"></script>
<script type="text/javascript">
/* Set Timepicker to component */
function setTimepicker(componentObj) {
$(componentObj).timepicker({ show24Hours: false, timeFormat: 'hh:mm TT', ampm: true});
}
</script>
<apex:form id="frmMain">
<!-- Date -->
<apex:inputText value="{!dateSampled}" onfocus="DatePicker.pickDate(false, this.id, false);"/>
<!-- Time -->
<apex:inputText value="{!timeSampled}" onfocus="setTimepicker(this);"/>
</apex:form>
</apex:page>
于 2012-10-17T04:41:49.147 に答える
2
2 つのフィールド (1 つの日付と別の時間のテキスト フィールド) を使用できませんか。次に、これらのフィールドを日時式フィールドに連結します。これは役に立ちませんか?
于 2012-10-06T19:28:22.907 に答える
2
時間がオプションの場合は、そのために 00 を使用します。
Datetime myDate = datetime.newInstance(2012, 10, 5, 00, 00, 0);
于 2012-10-05T06:24:01.270 に答える