This is a migrated thread and some comments may be shown as answers.

How to format TimePicker output?

5 Answers 120 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
dean.carrefour
Top achievements
Rank 1
dean.carrefour asked on 14 Feb 2012, 11:51 PM
I'm using a TimePicker in my project.  Right now if I pick 2:00 PM from the list, the data I get out of the control says "2/14/2012 2:00:00 PM"
I want just "2:00 PM".  I'm using the latest build of the controls.

The DatePicker is the same way, I have to trim the time off of it to get it the way I want it.

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Feb 2012, 05:34 AM
Hello,

Try the following javascript.
JS:
function OnClientClick()
 {
   var RadTimePicker1 = $find("<%= RadTimePicker1.ClientID %>");
   var time= RadTimePicker1.get_dateInput().get_value();
 }

Thanks,
Princy.
0
Richard
Top achievements
Rank 1
answered on 15 Feb 2012, 04:43 PM
Dean:

If you're trying to access the Short Time String value on the server-side, you can do the following:

protected void RadTimePicker1_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
{
    Label3.Text = "You selected: " + e.NewDate.Value.ToShortTimeString();
}

Cheers!
0
dean.carrefour
Top achievements
Rank 1
answered on 15 Feb 2012, 06:38 PM
I tried to use Jumpstarts code but I can't get it to convert to VB correctly.  I'm using a RadTimePicker named timeEvent and just trying to read the short time out of it (2:00 PM) instead of the long time (2/15/2012 2:00:00 PM).

I can't belive there's not a mask or some other method to format the output the way I want it.  It shows up correctly in the textbox beside the clock button once a time is picked.
0
Accepted
Richard
Top achievements
Rank 1
answered on 15 Feb 2012, 07:10 PM
Dean:

You can take a look at the VB.NET code behind on the Calendar/Validation online demo. It does use a format mask, as you hoped.

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
 
Namespace Telerik.Web.Examples.Calendar.DateTimePicker.Validation
    Partial Public Class DefaultVB
        Inherits System.Web.UI.Page
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
 
            Label1.Text = "You selected date range <br/>from <b>" & _
                String.Format("{0:hh:mm tt}", RadTimePicker1.SelectedDate) & "</b> to <b>" & _
                String.Format("{0:hh:mm tt}", RadTimePicker2.SelectedDate) & "</b>"
        End Sub
    End Class
End Namespace
 
Cheers!
0
dean.carrefour
Top achievements
Rank 1
answered on 15 Feb 2012, 07:43 PM
This string did it.  Thanks.

String.Format("{0:hh:mm tt}", RadTimePicker1.SelectedDate)
Tags
General Discussions
Asked by
dean.carrefour
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Richard
Top achievements
Rank 1
dean.carrefour
Top achievements
Rank 1
Share this question
or