telerik:RadTimePicker get only time using javascript - javascript

I have telerik:RadTimePicker control and I want to get the time using javascript. In telerik web site they have mentioned
var picker = $find("<%=RadDateTimePicker1.ClientID%>");
var view = picker.get_timeView();
alert(view.getTime());
But when I tried this I get all the details including time information.
Tue Feb 26 2013 05:00:00 GMT+0530 (Sri Lanka Standard Time)
What I really need is 05:00:00
Any easy way ?

the getTime() is returning you a JavaScript Date object. You will need to use the JavaScript Date constructs to extract the Hours:Minutes:Seconds kind of data. Here is a link to JavaScript date documentation: http://www.w3schools.com/jsref/jsref_obj_date.asp
you can just use the get_selectedDate() on the picker. This method too returns you a javaScript Date object. You can then extract the hours, minutes, seconds from the date object. we don't have any specific time string returning property on the picker object model.

Related

How to convert all dates from UTC to Local time using angularJS?

I have very complex structure that I receive from server-side code.
This structure has many Date properties (of type Date).
These Date properties contain dates in UTC.
I need to convert all of them to Local.
Is there any way to do this in angularJS?
Instead of doing this one-by-one?
Maybe some global setting or options that will instruct angular to convert dates into Local automatically?
Thanks.
append " UTC" to the backend time and run that through new Date(). It'll give you the local time offset.
var backEndDate = "2016-10-20 10:00 AM" + " UTC";
console.log(new Date(backEndDate));
The first approach is change your web service to return the utc date using ISO 8601 format.
For example: "2016-10-07T22:01:00Z"
If the web service return's the date using this ISO is easy to represents the date in local time of user because the browser instances the date based on your current time zone.
For example: if i open my browser console and run this javascript code:
new Date("2016-10-07T22:01:00Z")
I will receive the date based on my time zone, that is GMT-0300.
Fri Oct 07 2016 19:01:00 GMT-0300 (SA Eastern Standard Time)
So, for angularjs code you just need write::
{{"2016-10-07T22:01:00Z" | date}}
i will receive this result:
Oct 7, 2016
Check the filter for date here
For use the filter correctly. For example:
{{"2016-10-07T22:01:00Z" | date: 'MM/dd/yyyy HH:mm'}}
The result is:10/07/2016 19:01
The second approach is convert the date from your web service for the ISO 8601 format.
Actually i had the same problem and the client web service sends me the date just like this: "2016-10-07 22:01:00"
So, i wrote a simple code to convert this date format to ISO 8601.

Date is in string format

I am a newbie in javascript, come to my question.
I am using ionic 2 build application in which i am using date time picker for taking a time.
I am getting a a time format is in the "hh:mm" using time picker. eg(10:11) which is in string format and i am using Date() function which give me date is in something like
"Mon Aug 01 2016 01:32:03 GMT-0700 (Pacific Daylight Time)"
I want to replace "hh:mm"(01:32) from Date object with my string output of "hh:mm"(10:11) and then want to convert that into new Date object.
I also tried split and slice function but doesn't work.
If i get some guide about this will be very helpful.
I will be very helpful to all of you.
thanks
First of all, read up on Date.
In your case, the following code is a starting point.
var d = new Date();
d.setHours('10');
d.setMinutes('11');
Of course, you should exchange '10' and '11' with your picker data. Also, there are many other methods you can use on the Date object.

How to keep the Date as it is without being converted into local time zone?

I am having issue with the localtime zone things in javascript. If I got a string value from the server is "2014-02-03T00:00:00.000Z", once I pass it into Date object new Date('2014-02-03T00:00:00.000Z'), the new date object will be in localtime zone ex. Sun Feb 02 2014 18:00:00 GMT-0600 (CST). How to keep the value as 'Mon Feb 03 2014 00:00:00' ? I see a lot of people is using moment.js for dealing date, but I don't find any help with this issue.
Thanks
You can use getUTCDate() method. It will return you correct date.
http://jsbin.com/zizukapuba/1/edit?output
It will convert the date into required format with reference to system local timezone.
NOTE: If you use, the getISOString() method, then it will again make the changes with reference to your local time, that is, GMT -6.00.
The Date object stores your date as "2014-02-03T00:00:00.000Z".
When you display your Date object, the toString() function is used to get a string to display the date. toString() displays the date using the local time zone. Try using the toISOString() function or toUTCDateString().

How do I convert to browser timezones using phstc dateFormat?

EDIT : Btw, I have no idea why this question was marked as a duplicate. The answers in the original question does not work for me. i.e, getting wrong results and stuffs. Furthermore, none of the answers deal with phstc's dateFormat function. Do correct me if I'm wrong. Btw, I have solved this question. Do take a look at my answer.
I want to change a UTC datetime to my browser's timezone. I'm using phstc's dateFormat in pure javascript form. Let's say I convert a datetime of 2014-06-27 07:11:16 using a javascript Date() function. The result I got was
Fri Jun 27 2014 07:11:16 GMT+0800 (Malay Peninsula Standard Time)
Then when I use phstc's toBrowserTimeZone function, it still returns me the same datetime. I wanted to get something like 2014-06-27 15:11:16
Here is the code below:
var originalDateTime = new Date(`2014-06-27 07:11:16`);
alert(DateFormat.format.toBrowserTimeZone(originalDateTime,"yyyy/MM/dd HH:mm:ss"));
According to this statement in phstc's dateFormat page,
value = String representing date in ISO time (ā€œ2013-09-14T23:22:33Zā€) or String representing
default JAXB formatting of java.util.Date (ā€œ2013-09-14T16:22:33.527-07:00ā€) or String representing
Unix Timestamp (Sat Sep 14 2013 16:22:33 GMT-0700 (PDT)) or javascript date object.
JS Date object should work but unfortunately, it didn't. Well, I got it fixed by changing the datetime to other formats stated above first before calling the toBrowserTimeZone() function. For example,
var originalDateTime = DateFormat.format.date('2014-06-27 07:11:16',"yyyy-MM-ddTHH:mm:ssZ");
var newDateTime = DateFormat.format.toBrowserTimeZone(originalDateTime);

Convert Created Time using Javascript FQL Facebook

I am using Facebook FQL to get photos and the time when they were created. The problem is am getting the created time as some long integer value e.g. 1306776492.
Now I am unable to convert it to proper date time using javascript.
Can anyone point me in the right direction
You can set a Date objects time with the setTime method.
var d = new Date();
d.setTime(1306776492*1000);
document.write(d);
returns
Mon May 30 2011 20:28:12 GMT+0300 (FLE
Daylight Time)
http://jsfiddle.net/niklasvh/ANRcm/
If you want the date to be printed in a different format, just have a look at the other methods available for Date()

Categories

Resources