Find it difficult to get the current date and time? Then read on, I this tutorial I demonstrate getting current date and time in different programming languages.
Java
Using Calendar
output: 28/6/2012
[sourcecode language="java"]
Calendar cal = new GregorianCalendar();
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
int day = cal.get(Calendar.DAY_OF_MONTH);
System.out.println("Current date : " + day + "/" + (month + 1) + "/" + year);
[/sourcecode]
Using SimpleDateFormat
output: 28/06/2012
[sourcecode language="java"]
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date date = new Date();
String sDate= sdf.format(date);
[/sourcecode]
C#
Using DateTime format
output: Jun Fri 27 11:41 2012
[sourcecode language="csharp"]
DateTime time = DateTime.Now; // Use current time
string format = "MMM ddd d HH:mm yyyy"; // Use this format
Console.WriteLine(time.ToString(format));
[/sourcecode]
Some other patterns for DateTime
MMM : display three-letter month
ddd : display three-letter day of the WEEK
d : display day of the MONTH
HH : display two-digit hours on 24-hour scale
mm : display two-digit minutes
yyyy : display four-digit year
Single-letter format
output :
6/28/2012
Thursday, June 28, 2012
Thursday, June 28, 2012 11:36 AM
Thursday, June 28, 2012 11:36:21 AM
6/28/2012 11:36 AM
6/28/2012 11:36:21 AM
June 28
June 28
2012-06-28T11:36:21.8863219+05:30
2012-06-28T11:36:21.8863219+05:30
2012-06-28T11:36:21
11:36 AM
11:36:21 AM
2012-06-28 11:36:21Z
Thursday, June 28, 2012 6:06:21 AM
June, 2012
June, 2012
[sourcecode language="csharp"]
DateTime now = DateTime.Now;
Console.WriteLine(now.ToString("d"));
Console.WriteLine(now.ToString("D"));
Console.WriteLine(now.ToString("f"));
Console.WriteLine(now.ToString("F"));
Console.WriteLine(now.ToString("g"));
Console.WriteLine(now.ToString("G"));
Console.WriteLine(now.ToString("m"));
Console.WriteLine(now.ToString("M"));
Console.WriteLine(now.ToString("o"));
Console.WriteLine(now.ToString("O"));
Console.WriteLine(now.ToString("s"));
Console.WriteLine(now.ToString("t"));
Console.WriteLine(now.ToString("T"));
Console.WriteLine(now.ToString("u"));
Console.WriteLine(now.ToString("U"));
Console.WriteLine(now.ToString("y"));
Console.WriteLine(now.ToString("Y"));
[/sourcecode]
Using Date strings to control the output
output:
Thursday, June 28, 2012
12:03:53 PM
6/28/2012
12:03 PM
6/28/2012 12:03:53 PM
[sourcecode language="csharp"]
DateTime now = DateTime.Now;
Console.WriteLine(now.ToLongDateString());
Console.WriteLine(now.ToLongTimeString());
Console.WriteLine(now.ToShortDateString());
Console.WriteLine(now.ToShortTimeString());
Console.WriteLine(now.ToString());
[/sourcecode]
PHP
output : 2012-06-28 17:33:07
[sourcecode language="php"]
$date = date('Y-m-d H:i:s');
echo $date;
[/sourcecode]
output : 2012/06/28 17:33:07
[sourcecode language="php"]
$date = date('Y/m/d H:i:s');
echo $date;
[/sourcecode]
This time is based on the default server time zone. To get the time in a different time zone it should be set first.
[sourcecode language="php"]
date_default_timezone_set('Australia/Sydney');
$date = date('Y/m/d H:i:s');
echo $date;
[/sourcecode]
JavaScript
output : Thursday, June 28, 2012
[sourcecode language="javascript"]
<script type="text/javascript"><!--
var now = new Date();
var Weekday = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var Month = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
document.write(Weekday[now.getDay()]+", "+Month[now.getMonth()]+" "+now.getDate()+", "+now.getFullYear());
//--></script>
[/sourcecode]
output : 6/28/2012
[sourcecode language="javascript"]
<script type="text/javascript"><!--
var now = new Date();
document.write((now.getMonth()+1)+"/"+now.getDate()+"/"+now.getFullYear());
//--></script>
[/sourcecode]
output : 06/28/2012
[sourcecode language="javascript"]
<script type="text/javascript"><!--
var now = new Date();
var month = now.getMonth()+1;
if( month < 9 ) { month = "0"+month; }
var day = now.getDate();
if( day < 9 ) { day = "0"+day; }
document.write(month+"/"+day+"/"+now.getFullYear());
//--></script>
[/sourcecode]
ios
[sourcecode language="objc"]
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"hh:mm a"];
NSString *str_date = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"str_date:%@",str_date);
[/sourcecode]
Showing posts with label Windows Phone 7. Show all posts
Showing posts with label Windows Phone 7. Show all posts
Thursday, June 28, 2012
Thursday, June 14, 2012
Get Directions with Bing Maps using Geocordinates.
With Bing Map API, you can easily get the directions to some place. You only need to know the start location and end location. If this start location is not specified, your current location is treated as the start.
In this tutorial we use Bing Maps Directions Task which is one of the many launchers bundled with Windows Phone7 Mango series. Hopefully, they make developer's life easy. They are really useful when integrate social sharing features to your applicaton. Otherwise you need to deal with OAth protocol for a considerable amount of time. You do not need to touch those dirty ...
Enough pep talk. Let's get started.
You have two options to enter location details either by text based or geocordinates which are in latitude and longitude format. These two methods are demonstrated below.
Text based location
[sourcecode language="csharp"]
BingMapsDirectionsTask bmDirectionTask = new BingMapsDirectionsTask();
LabeledMapLocation start = new LabeledMapLocation("Sydney", null);
LabeledMapLocation end = new LabeledMapLocation("Perth", null);
bmDirectionTask.Start = start;
bmDirectionTask.End = end;
bmDirectionTask.Show();
[/sourcecode]
Based on geocordinates
[sourcecode language="csharp"]
BingMapsDirectionsTask bingMapsDirectionsTask = new BingMapsDirectionsTask();
GeoCoordinate userLocation = new GeoCoordinate(33.8683,151.2086);
LabeledMapLocation start = new LabeledMapLocation("From", userLocation);
bingMapsDirectionsTask.Start = start;
GeoCoordinate placeLocation = new GeoCoordinate();
LabeledMapLocation end = new LabeledMapLocation(31.9554,115.8585);
bingMapsDirectionsTask.End = end;
bingMapsDirectionsTask.Show();
[/sourcecode]
In this tutorial we use Bing Maps Directions Task which is one of the many launchers bundled with Windows Phone7 Mango series. Hopefully, they make developer's life easy. They are really useful when integrate social sharing features to your applicaton. Otherwise you need to deal with OAth protocol for a considerable amount of time. You do not need to touch those dirty ...
Enough pep talk. Let's get started.
You have two options to enter location details either by text based or geocordinates which are in latitude and longitude format. These two methods are demonstrated below.
Text based location
[sourcecode language="csharp"]
BingMapsDirectionsTask bmDirectionTask = new BingMapsDirectionsTask();
LabeledMapLocation start = new LabeledMapLocation("Sydney", null);
LabeledMapLocation end = new LabeledMapLocation("Perth", null);
bmDirectionTask.Start = start;
bmDirectionTask.End = end;
bmDirectionTask.Show();
[/sourcecode]
Based on geocordinates
[sourcecode language="csharp"]
BingMapsDirectionsTask bingMapsDirectionsTask = new BingMapsDirectionsTask();
GeoCoordinate userLocation = new GeoCoordinate(33.8683,151.2086);
LabeledMapLocation start = new LabeledMapLocation("From", userLocation);
bingMapsDirectionsTask.Start = start;
GeoCoordinate placeLocation = new GeoCoordinate();
LabeledMapLocation end = new LabeledMapLocation(31.9554,115.8585);
bingMapsDirectionsTask.End = end;
bingMapsDirectionsTask.Show();
[/sourcecode]
Tuesday, June 12, 2012
Customized PushPin on bing Map
This tutorial demonstrates how to create a pushpin from a specified image.

First add your image to the silverlight project.
Add the bing map control to the page.
[sourcecode language="xml"]
<my:Map x:Name="map" CredentialsProvider="YOUR_BING_MAP_API_KEY" Height="600" >
</my:Map>
[/sourcecode]
Define a control template inside the required page or inside App.xaml page. Things we declare in App.xaml are global. If you need to use bing map on several pages App.xaml is preferred. So we maintain code reusability.
For this example, I define control template in one of my inside page within PhoneApplicationPage.Resources section.
[sourcecode language="xml"]
<phone:PhoneApplicationPage.Resources>
<ControlTemplate x:Key="PushpinControlTemplate" TargetType="my:Pushpin">
<Image x:Name="pinImage" Height="64" Source="/Images/push_pin.png"/>
</ControlTemplate>
</phone:PhoneApplicationPage.Resources>
[/sourcecode]
Value of TargetType attribute consists of your bing map control namespace which can be found in your xaml page. Here, it 's 'my'.
To display the pushpin add this code.
Here we should specify the relevant control template that we need.
[sourcecode language="csharp"]
Pushpin pin1 = new Pushpin();
pin1.Location = new GeoCoordinate(51.5171, 0.1062);
pin1.Template = (ControlTemplate)(this.Resources["PushpinControlTemplate"]);
map.Children.Add(pin1);
map.SetView(pin1.Location, 10);
[/sourcecode]
That 's it!
If you can not see the pushpin, set the Build Action of the image to Content and try.
First add your image to the silverlight project.
Add the bing map control to the page.
[sourcecode language="xml"]
<my:Map x:Name="map" CredentialsProvider="YOUR_BING_MAP_API_KEY" Height="600" >
</my:Map>
[/sourcecode]
Define a control template inside the required page or inside App.xaml page. Things we declare in App.xaml are global. If you need to use bing map on several pages App.xaml is preferred. So we maintain code reusability.
For this example, I define control template in one of my inside page within PhoneApplicationPage.Resources section.
[sourcecode language="xml"]
<phone:PhoneApplicationPage.Resources>
<ControlTemplate x:Key="PushpinControlTemplate" TargetType="my:Pushpin">
<Image x:Name="pinImage" Height="64" Source="/Images/push_pin.png"/>
</ControlTemplate>
</phone:PhoneApplicationPage.Resources>
[/sourcecode]
Value of TargetType attribute consists of your bing map control namespace which can be found in your xaml page. Here, it 's 'my'.
To display the pushpin add this code.
Here we should specify the relevant control template that we need.
[sourcecode language="csharp"]
Pushpin pin1 = new Pushpin();
pin1.Location = new GeoCoordinate(51.5171, 0.1062);
pin1.Template = (ControlTemplate)(this.Resources["PushpinControlTemplate"]);
map.Children.Add(pin1);
map.SetView(pin1.Location, 10);
[/sourcecode]
That 's it!
If you can not see the pushpin, set the Build Action of the image to Content and try.
Roundedc Corner Rectangles
[sourcecode language="xml"]
<Rectangle x:Name="rec_1" Width="100" Height="100" RadiusX="20" RadiusY="20" Fill="Blue" />
[/sourcecode]
RadiusX determines the radius of the corners on the x-axis and RadiusY determines the radius of the corners on the y-axis.
<Rectangle x:Name="rec_1" Width="100" Height="100" RadiusX="20" RadiusY="20" Fill="Blue" />
[/sourcecode]
RadiusX determines the radius of the corners on the x-axis and RadiusY determines the radius of the corners on the y-axis.
Monday, June 11, 2012
Send SMS with Windows Phone 7
[sourcecode language="csharp"]
SmsComposeTask smsComposeTask = new SmsComposeTask();
smsComposeTask.To = textBox1.Text; // Get recepient's number
smsComposeTask.Body = textBox2.Text; //Get message body
smsComposeTask.Show(); // Invoke the native sms task
[/sourcecode]

SMS Sending user interface.

After Send button is clicked it opens up the native SMS application with message & phone number filled.

Once the user clicks on Send Button on native SMS application, SMS will be sent.
SmsComposeTask smsComposeTask = new SmsComposeTask();
smsComposeTask.To = textBox1.Text; // Get recepient's number
smsComposeTask.Body = textBox2.Text; //Get message body
smsComposeTask.Show(); // Invoke the native sms task
[/sourcecode]
SMS Sending user interface.
After Send button is clicked it opens up the native SMS application with message & phone number filled.
Once the user clicks on Send Button on native SMS application, SMS will be sent.
Subscribe to:
Posts (Atom)
How to enable CORS in Laravel 5
https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...
-
I have already written several posts regarding Android database applications. This post might be similar to those tuts. However this is more...
-
< Requirements Java Development Kit (JDK) NetBeans IDE Apache Axis 2 Apache Tomcat Server Main Topics Setup Development Environ...