af:inputDate is returning GMT instead of user selected date in ADF - timezone

I am using af:inputDate tag to capture the date in adf.
My web page looks like -
The date gets stored at startDate (which is java.util.Date).
Now after
DataObjectEncodingUtils.encodeDate(startDate)
it is returning 2014-02-01 18:30:00 which is exactly 5.30 hours behind the selected date.
Here is the entry details in my trinidad-config.xml -
<?xml version="1.0" encoding="windows-1252"?>
<trinidad-config xmlns="http://myfaces.apache.org/trinidad/config">
<skin-family>mySkin</skin-family>
<formatting-locale>en_GB</formatting-locale>
<time-zone>Asia/Calcutta</time-zone>
<!--<time-zone>IST</time-zone>-->
</trinidad-config>
Am i missing something ?
-Amit

Have you tried using an component together with the inputDate?
You can set the date format and the timezone in which you want the date displayed.

Related

How do you convert a date in XSLT2.0?

How can I format the resulted date below to display like this: MM/dd/YYYY (e.g.: 05/04/2020)?
The $getField will be: 2020-05-04T15:00:12
My value in the template is:
<xsl:value-of select="xs:dateTime($getField)+xs:dayTimeDuration('PT1H')"/>
Currently, it displays as follows: 2020-04-05T16:00:12
Each time I try using format-date, I get an error.
Also, if I will use xs:date(xs:dateTime($getField)+xs:dayTimeDuration('PT12H')), it will display only the date, without hours/minutes, but still not sure how can I change the order for date?
Thanks!
Use the format-dateTime() function with the desired picture "[M01]/[D01]/[Y0001]":
format-dateTime(xs:dateTime($getField)+xs:dayTimeDuration('PT1H'), "[M01]/[D01]/[Y0001]")

Save task with a specific date and timezone

It's a rails project. I have a form where the user can schedule tasks. For the moment I get the timezone of the browser with :
var currentTime = new Date();
var timezone_offset = currentTime.getTimezoneOffset()
And then I use it in my controller. But the problem is :
How can I save the date to be scheduled to the right moment?
I thought the answer will be to parse the date from my form and then change the offset but it doesn't work:
> time = Time.parse("2015/11/30 12:00")
=> 2015-11-30 12:00:00 +0100
> time.change(offset: '+02:00')
=> 2015-11-30 12:00:00 +0100
Maybe the answer is to create a Time.new?
My heroku server is on UTC. Some users on CET.
You would be better off getting your form to submit the time in UTC format.
Using something like moment.js (http://momentjs.com/) you can get their local time in the browser and display the date/time in their local format, but submit the UTC counterpart to the server when submitting your form.

DateTime from WebApi to Breeze is transformed with the Time Localization

I have a form on which I set a start Date and a finish Date for a entity.
On the Web Api side, before saving the date to the database,I set the start date: 2013-09-25 00:00:00.000 and the the end date as 2013-09-26 23:59:59.000.
var vote = (VotingSet)Entity;
vote.Start = new DateTime(vote.Start.Year, vote.Start.Month, vote.Start.Day, 0, 0, 0, 0);
vote.End = new DateTime(vote.End.Year, vote.End.Month, vote.End.Day, 23, 59, 58);
This is from the JSON that is send to the rest service looks like this:
Start: "2013-09-25T00:00:00.000Z"
End: "2013-09-26T00:00:00.000Z"
After the save, in the javascript client, the entity is updated with the new key and with the properties that come from the server.
The observable date objects will have the following value
Start: Wed Sep 25 2013 03:00:00 GMT+0300 (GTB Daylight Time)
End: Fri Sep 27 2013 02:59:58 GMT+0300 (GTB Daylight Time)
This is what i am getting back from the server
Start: "2013-09-25T00:00:00.000"
End: "2013-09-26T23:59:58.000"
How can i make sure that the hours in my object are not modified?
EDIT:
There is a a good explaniation here on what's happening with the datetime in javascript.
In the end i used this snipped to solve my problem:
breeze.DataType.parseDateFromServer = function (source) {
var date = moment(source);
return date.toDate();
};
It override's breeze own function with adds a time offset to the datetime.
Breeze does not manipulate the datetimes going to and from the server in any way EXCEPT to add a UTZ timezone specifier to any dates returned from the server that do not already have one. This is only done because different browsers interpret dates without a timezone specifier differently and we want consistency between browsers.
This is discussed in more detail in the answer posted here.
You are passing ISO8601 formatted timestamps, which is good. When you pass the Z at the end, you are indicating that the timestamp represents UTC. When you load those into JavaScript, it's going to take that into account.
You still need to show more code if you are looking for a useful response. What you've currently described from .NET doesn't quite line up with the timestamps you've provided. And it seems like most of this problem has to do with JavaScript and you haven't yet shown any of that code, so I can only guess what you might be doing. Please update your question, and understand that we have no knowledge of your system other than what you show us.
It's possible you may find moment.js to be useful in this scenario, but I can't elaborate further without seeing the relevent JavaScript code.

Modx Evo Date Difference Snippet

Using Modx evo, I am trying to use the following snippet to display the date difference between published date and current date (in days), but getting weird output. What am I doing wrong?
<?php
$date2=$modx->documentObject['createdon'];
$date1=time();
$dateDiff = $date1 - $date2;
$daysOld = floor($dateDiff/(60*60*24));
return $daysOld;
?>
The thing is that the date is stored as a SQL-date, not a timestamp.
Read the docs: http://rtfm.modx.com/display/revolution20/Date+Formats
So, this should work:
$dateDiff = $time() - strtotime($modx->documentObject['createdon']);
$daysOld = floor($dateDiff/(60*60*24));
return $daysOld;

how to get timezone from a calendar

I am trying to get the timezone from native calendar using the following code but i am getting the timezone has Asia/Calcutta instead of just 'IST'
Calendar calendarLocal = Calendar.getInstance();
// fetches time zone
TimeZone timeZone = calendarLocal.getTimeZone();
System.out.println("Time Zone getAvailableIDs() --->"+timeZone.getAvailableIDs());
String[] x=timeZone.getAvailableIDs();
for(int i=0;i<x.length;i++){
System.out.println("Time Zone IDs-->"+x[i]);
}
System.out.println("Time Zone ID--->"+timeZone.getID());
System.out.println(" Calender Default-------->>>"+timeZone.getDefault());
System.out.println("Time Zone --->"+timeZone.getTimeZone(timeZone.getID()));
Here TimeZone is Asia/Calcutta i need it to print IST
BlackBerry Java doesn't give you the time zone short codes, at least not reliably (it only gaurantees to know about the "GMT" code). You can see my answer here for information about how to code a mapping between strings like "Asia/Calcutta" and "IST". (my method mapTimeZoneCodes() in that example)
I provide a template method for setting up the mapping, and a link to this article on Desktop Java, which seems to have a pretty complete list of the time zone codes, and how to map codes to the long Java time zone strings.
It will be boring work to copy the strings into my template, but once you have it, you'll be able to easily lookup the short code based on the long name:
String longName = timeZone.toString();
String shortCode = (String)_timeZones.get(longName);

Resources