static SegmentedTimeline() { int rawOffset = TimeZone.getDefault().getRawOffset(); SimpleTimeZone.__\u003Cclinit\u003E(); SegmentedTimeline.NO_DST_TIME_ZONE = (TimeZone) new SimpleTimeZone(rawOffset, new StringBuffer().append("UTC-").append(rawOffset).toString()); GregorianCalendar.__\u003Cclinit\u003E(); GregorianCalendar gregorianCalendar = new GregorianCalendar(SegmentedTimeline.NO_DST_TIME_ZONE); ((Calendar) gregorianCalendar).set(1900, 0, 1, 0, 0, 0); ((Calendar) gregorianCalendar).set(14, 0); while (((Calendar) gregorianCalendar).get(7) != 2) ((Calendar) gregorianCalendar).add(5, 1); SegmentedTimeline.FIRST_MONDAY_AFTER_1900 = ((Calendar) gregorianCalendar).getTime().getTime(); }
/// <summary> /// Toes the date time. /// </summary> /// <param name="javaDate">The java date.</param> /// <returns></returns> public static DateTime ToDateTime(Date javaDate) { var calender = new GregorianCalendar(); calender.setTime(javaDate); return new DateTime(calender.get(Calendar.YEAR), calender.get(Calendar.MONTH) + 1, calender.get(Calendar.DAY_OF_MONTH), calender.get(Calendar.HOUR_OF_DAY), calender.get(Calendar.MINUTE), calender.get(Calendar.SECOND), DateTimeKind.Local ); }
// jsc: seems like we need atleast one in and one out string :) public void CreateEvent(string Title, string Location, string Description, Action<string> y) { // http://developer.android.com/reference/android/provider/CalendarContract.EventsColumns.html#DESCRIPTION Console.WriteLine("CreateEvent " + new { Title, Location, Description }); Intent calIntent = new Intent(Intent.ACTION_INSERT); // when one opens browser in android calendar stays hidden.. // http://stackoverflow.com/questions/2232238/how-to-bring-an-activity-to-foreground-top-of-stack //calIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); calIntent.setType("vnd.android.cursor.item/event"); calIntent.putExtra("title", Title); calIntent.putExtra("eventLocation", Location); calIntent.putExtra("description", Description); GregorianCalendar calDate = new GregorianCalendar(2012, 7, 15); calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true); calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calDate.getTimeInMillis()); calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, calDate.getTimeInMillis()); calIntent.putExtra("accessLevel", 0x00000002); calIntent.putExtra("availability", 0x00000000); calIntent.putExtra("rrule", "FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH"); // well spawn another activity/thread ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext.startActivity(calIntent); y(""); }
protected override void onCreate(Bundle savedInstanceState) { base.onCreate(savedInstanceState); var sv = new ScrollView(this); var ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); sv.addView(ll); new Button(this) .WithText("Create Event!") .AttachTo(ll) .AtClick( b => { b.setText("Done!"); // http://developer.android.com/reference/android/provider/CalendarContract.EventsColumns.html#DESCRIPTION Intent calIntent = new Intent(Intent.ACTION_INSERT); calIntent.setType("vnd.android.cursor.item/event"); calIntent.putExtra("title", "My House Party"); calIntent.putExtra("eventLocation", "My Beach House"); calIntent.putExtra("description", "A Pig Roast on the Beach"); GregorianCalendar calDate = new GregorianCalendar(2012, 7, 15); calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true); calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calDate.getTimeInMillis()); calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, calDate.getTimeInMillis()); //ttdw calIntent.putExtra("accessLevel", 0x00000002); calIntent.putExtra("availability", 0x00000000); calIntent.putExtra("rrule", "FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH"); startActivity(calIntent); } ); var COLS = new[] { "title", "dtstart" }; var at = new TextView(this).AttachTo(ll); at.setText("at " + CalendarContract.Events.CONTENT_URI.ToString()); // from t in calendars // select t.title var mCursor = this.getContentResolver().query( CalendarContract.Events.CONTENT_URI, COLS, null, null, null ); mCursor.moveToLast(); var tv = new TextView(this).AttachTo(ll); tv.setText("n/a"); Action update = delegate { var title = ""; var start = ""; var w = ""; //Format df = android.text.format.DateFormat.getDateFormat(this); //Format tf = android.text.format.DateFormat.getTimeFormat(this); //try //{ title = mCursor.getString(0); start = ((object)mCursor.getLong(1)).ToString(); w += title; w += " at "; w += start; tv.setText(w); //} //catch //{ // tv.setText("n/a error"); // throw; //} }; Button prev, next = null; prev = new Button(this) .WithText("Prev") .AttachTo(ll) .AtClick( b => { if (!mCursor.isFirst()) { mCursor.moveToPrevious(); next.setEnabled(true); } else b.setEnabled(false); update(); } ); next = new Button(this) .WithText("Next") .AttachTo(ll) .AtClick( b => { if (!mCursor.isLast()) { mCursor.moveToNext(); prev.setEnabled(true); } else b.setEnabled(false); update(); } ); update(); this.setContentView(sv); }
public static void main(string[] args) { GregorianCalendar gregorianCalendar1 = new GregorianCalendar(2006, 10, 1, 0, 0, 0); GregorianCalendar gregorianCalendar2 = new GregorianCalendar(2006, 10, 1, 11, 37, 43); ((Calendar) gregorianCalendar2).set(14, 123); System.get_out().println("Default: "); RelativeDateFormat relativeDateFormat = new RelativeDateFormat(((Calendar) gregorianCalendar1).getTime().getTime()); System.get_out().println(((DateFormat) relativeDateFormat).format(((Calendar) gregorianCalendar2).getTime())); System.get_out().println(); System.get_out().println("Hide milliseconds: "); relativeDateFormat.setSecondFormatter((NumberFormat) new DecimalFormat("0")); System.get_out().println(((DateFormat) relativeDateFormat).format(((Calendar) gregorianCalendar2).getTime())); System.get_out().println(); System.get_out().println("Show zero day output: "); relativeDateFormat.setShowZeroDays(true); System.get_out().println(((DateFormat) relativeDateFormat).format(((Calendar) gregorianCalendar2).getTime())); System.get_out().println(); System.get_out().println("Alternative suffixes: "); relativeDateFormat.setShowZeroDays(false); relativeDateFormat.setDaySuffix(":"); relativeDateFormat.setHourSuffix(":"); relativeDateFormat.setMinuteSuffix(":"); relativeDateFormat.setSecondSuffix(""); System.get_out().println(((DateFormat) relativeDateFormat).format(((Calendar) gregorianCalendar2).getTime())); System.get_out().println(); }