here i am using the blackberry 8520 to display the timepicker. i want to set the time as 10:00:00 upto when the timepickerstarts to change the time in the simuator
public void run()
{
//create timepicker by using this method
//by using this simpledateformat we set time format
SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss aa");
DateTimePicker datepicker = DateTimePicker.createInstance(Calendar.getInstance(),null,"hh:mm:ss aa");
datepicker.doModal();
StringBuffer datestrTime=new StringBuffer();
//by using this method we get date from system date&time
Calendar cal = datepicker.getDateTime();
timeFormat.format(cal,datestrTime, null);
// we are taking the current time from the system and displaying in the label field
time_picker.setText(datestrTime.toString());
}
use the below code:
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR,10);
cal.set(Calendar.MINUTE,00);
cal.set(Calendar.SECOND,00);
datepicker.setDateTime(cal);
datepicker.doModal();
Related
I would like to know how I can check if a users phone date and time are properly set.
You can use the NTP package to the network time protocol form http://pool.ntp.org
With this package, you can calculate the offset between the user time and network time
Example from documentation
import 'package:ntp/ntp.dart';
Future<void> main() async {
DateTime _myTime;
DateTime _ntpTime;
/// Or you could get NTP current (It will call DateTime.now() and add NTP offset to it)
_myTime = await NTP.now();
/// Or get NTP offset (in milliseconds) and add it yourself
final int offset = await NTP.getNtpOffset(localTime: DateTime.now());
_ntpTime = _myTime.add(Duration(milliseconds: offset));
print('My time: $_myTime');
print('NTP time: $_ntpTime');
print('Difference: ${_myTime.difference(_ntpTime).inMilliseconds}ms');
}
I'm using Vaadin Calendar component with EventProvider. It loads items corrently when displayed inititaly, but when I edit the calendar item it doest reflect changes on the screen. (caption name change or date changes) I even tried to set provider once again after entry update cal.setEventProvider(p); but it doesnt force calendar to fetch fresh data from provider. Any hint how to work with EventProvider and do entries updates on calendar?
I had a very similar problem a while back (Vaadin 7.1), and found out that the default implementation of ContainerEventProvider doesn't work properly. I do not remember all the details but my investigation showed a problem with the getEvents method. To solve it, I subclassed ContainerEventProvider with my own class and implemented an override of getEvents:
#Override
public List<CalendarEvent> getEvents(Date startDate, Date endDate) {
eventCache.clear();
// int[] rangeIndexes = getFirstAndLastEventIndex(startDate, endDate);
for (int i = 0; i < container.size(); i++) {
eventCache.add(getEvent(i));
}
return Collections.unmodifiableList(eventCache);
}
And this is the function that assigns a container to the calendar:
public void setCalendarContainerDataSource(Indexed ds) {
// this.vaadinCal.setContainerDataSource(ds); // this did't work
MyCalendarContainerEventProvider provider = new MyCalendarContainerEventProvider(ds);
provider.addEventSetChangeListener(new CalendarEventProvider.EventSetChangeListener() {
public void eventSetChange(EventSetChangeEvent changeEvent) {
vaadinCal.markAsDirty();
}
});
provider.addEventChangeListener(new EventChangeListener() {
public void eventChange(EventChangeEvent changeEvent) {
// Repaint if event changes
vaadinCal.markAsDirty();
}
});
vaadinCal.setEventProvider(provider);
}
I have a JSON grid that displays email templates but the problem is that the last change date shown is ahead of current date but the same record last change date is shown correctly when editing that record in MVC Edit view.
The Date in Json Format Returned is : Date(1362686659073)
But on the Edit page for same record Date is: 3/7/2013 12:04:19 PM i.e. Date(1362638059000)
There is a difference of around 13.5 hours in the same date.
this is my Code returning the Data to JSON
TemplateGridExt ext = new TemplateGridExt();
ext.Count = client.GetPagedGridCountEmailTmpl(filter);
ext.Data = result.EmailTmpl_Vs.ToList();
return this.Json(ext, JsonRequestBehavior.AllowGet);
Try to pass the data in some other format like string, then it should work fine.
Try this code -
First create a class like this -
public class TimeFormatter : DateTimeConverterBase
{
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return DateTime.Parse(reader.Value.ToString());
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteValue(((DateTime)value).ToString("yyyy/MM/dd"));//format for date
}
}
use this code to return the Json data to your view -
JsonSerializerSettings jSettings = new JsonSerializerSettings()
{
Formatting = Formatting.Indented,
DateTimeZoneHandling = DateTimeZoneHandling.Utc
};
jSettings.Converters.Add(new TimeFormatter());
JsonSerializer.Create(jSettings);
return JsonConvert.SerializeObject(data, jSettings);//'data' is list of objects to return to view.
dont forget to include there namespaces -
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
how can i receive a specific time zone for the received date-time from yahoo api?
and what is the default time zone?
http://hk.finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=USDHKD=x
http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=USDHKD=x
the received time is the same
private String GetRequest() throws ClientProtocolException, IOException{
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=USDHKD=x");
HttpResponse response = httpClient.execute(httpGet, localContext);
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent()
)
);
String line;
while ((line = reader.readLine()) != null) {
String[] RowData = line.split(",");
String value = RowData[1];//value = qoute
String date = RowData[2].replaceAll("\"", "");
String time = RowData[3].replaceAll("\"", "");
tvDateTimeValue.setText(date+"\t"+time);
return value;
}
return "";
}
Looks like it is America/New_York time zone.
These guys think so too (though not sure what is their source of information)
http://www.kksou.com/php-gtk2/Joomla-Gadgets/Yahoo-Stock-Quote-AJAX-version.php
It looks like the value is always given in UTC. That seems entirely reasonable to me. In particular, it's never ambiguous, and never subject to historical changes etc.
If you want to display the data in a particular time zone, perform the translation yourself. (I'd give sample code, but you haven't specified how you're accessing the API, e.g. which language you're using.)
I have few meeting request in my native calendar scheduled for different date and time,i am trying to read the entire events scheduled for a specific date using the folloing code.
private void getEvents() {
try {
EventList eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_ONLY);
Enumeration events = eventList.items();
while (events.hasMoreElements()) {
Event event = (Event)events.nextElement();
if(eventList.isSupportedField(Event.SUMMARY) && event.countValues(Event.SUMMARY) > 0) {
String subject = event.getString(Event.SUMMARY, 0);
Dialog.alert(subject);
}
}
}
catch (PIMException e) {
Dialog.alert(e.getMessage());
}
}
I am able to get the subject from native calendar ,but i want the code to read the meetings along with date and time,I am not able to do this.
The Date/Times of events are stored in the fields Event.START and Event.END as long values containing the number of milliseconds since the Unix epoch. See my answer to this question, and the API documents for the Event interface.