199 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
View.html.index cannot be resolved to a type
Wed, Mar 8th 2017 7
Kill Play Framework process
Thu, Jan 12th 2017 8
Play Framework project in production - Building process
Thu, Jan 12th 2017 14
Play Framework project in production - Application Secret
Thu, Jan 12th 2017 13
HTTP Routing in Play Framework
Sun, Dec 25th 2016 13
Template literals
Fri, Dec 23rd 2016 9
Actions in Play Framework 2.5
Thu, Dec 22nd 2016 6
Top 10
Insufficient memory - NSF pool is full
Mon, Jun 15th 2015 23
Domino and No trusted certificate found
Tue, Jan 28th 2014 19
Disabling certificate validation in Java
Mon, Apr 28th 2014 16
Refresh embedded view solutions
Mon, May 4th 2015 15
Play Framework project in production - Building process
Thu, Jan 12th 2017 14
HTTP Routing in Play Framework
Sun, Dec 25th 2016 13
Play Framework project in production - Application Secret
Thu, Jan 12th 2017 13
Track events using google analytics via hitCallback
Tue, Jul 8th 2014 11
Issues when importing WSDL files into Web Service Consumer
Mon, Sep 8th 2014 10
Setup Play Framework and TypeSafe on centOS
Wed, Oct 14th 2015 10


Transformation of String into Date respecting Locale
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
   

Let's say you need to parse a string into date and it is localized string (f.x. name of month on local language). In past I would definitely define an array with months and then parse a String to get a number of my month and then build a Date object. In Java it's pretty simple (almost 1 line of code).

Locale approach

package parser;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class parser {

public static void main(String[] args) throws ParseException {
Locale locale = new Locale("ru");
Date date = convertStringToDate("19 Сентября 2004", "d MMMM yyyy", locale);
System.out.println(date); // Sun Sep 19 00:00:00 CEST 2004
date = convertStringToDate("28 марта 2004", "d MMMM yyyy", locale);
System.out.print(date); // Sun Mar 28 00:00:00 CET 2004
}

public static java.util.Date convertStringToDate(String dateString, String format, Locale locale) throws ParseException {
return new SimpleDateFormat("d MMMM yyyy", locale).parse(dateString);
}
}

Alternatively, if you nned to define months yourself use DateFormatSymbols

Define symbols in DateFormatSymbols

package parser;

import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class parser {

public static void main(String[] args) throws ParseException {
String months[] = {"Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"};
DateFormatSymbols dfs = new DateFormatSymbols();
dfs.setMonths(months);

SimpleDateFormat sdf = new SimpleDateFormat("d MMMM yyyy");
sdf.setDateFormatSymbols(dfs);
System.out.print(sdf.parse("1 Май 2004"));
}
}


---------------------
http://feedproxy.google.com/~r/dpastov/~3/sorC-RSeVc8/transformation-of-string-into-date.html
Jul 04, 2015
4 hits



Recent Blog Posts
7
View.html.index cannot be resolved to a type
Wed, Mar 8th 2017 2:31p   Dmytro Pastovenskyi
If your play project in eclipse says that it can't resolve a type (see message below), but you are certain that everything should be fine$ View.html.index cannot be resolved to a type try to make a clean compile$ activator clean compile eclipseIt helped me to resolve my issue.
8
Kill Play Framework process
Thu, Jan 12th 2017 12:08p   Dmytro Pastovenskyi
When we run application in DEV mode (using command activator run) the process normally will be killed when terminal is closed. It's pretty easy since PID is started/closed automatically and therefore we do not care about it at all.Once we start application in PROD mode there is a file RUNNING_PID is created (./target/universal/stage/RUNNING_PID). There is a command (since version 2.4) in activator (stopProd) which will close PID$ activator stopProdAlternatively you can just kill process 'manua
14
Play Framework project in production - Building process
Thu, Jan 12th 2017 9:31a   Dmytro Pastovenskyi
We want to deploy our Play project to production environment. Create a binary version of applicationThere are two commands that can help you to make a build. Simply run dist or universal:packageZipTarball in Play console and wait$ dist$ universal:packageZipTarballResult will be a ZIP or TGZ file located in target/universal folder with everything needed for you project (it means you do not need to install SBT or Activator on your server, just pure Java). Once you extract ZIP you will find 2 runne
13
Play Framework project in production - Application Secret
Thu, Jan 12th 2017 7:00a   Dmytro Pastovenskyi
I am going to make series of articles about how to deploy Play Framework (version 2.5) application on centOS together with build system Jenkins. I'm doing this first time and want to document everything for myself and at the same time I hope it can be useful for somebody else as well. Before I wrote few articles how to setup hello-world project on centOS or macOS however now I'm going to work on production setup. I assume you already have you hello-world project and clean centOS environment.
13
HTTP Routing in Play Framework
Sun, Dec 25th 2016 7:55p   Dmytro Pastovenskyi
We are going to check how Play connect http requests with our code. F.x. when user hits http://localhost:9000/ what happens?HTTP RoutingThere is already built in http router in Play Framework. It allows to connect incoming requests with Play Action and therefore with public method in a controller class.Configuring HTTP RoutingNormally the configuration for HTTP routing is located in conf/routes. See example:# Static path GET /clients/all controllers.Clients.list() # Dynamic path GET /clients/:id
9
Template literals
Fri, Dec 23rd 2016 7:00a   Dmytro Pastovenskyi
I have to follow up with changes to ES6. Today I noticed template literals (there is also tagged template literals but that I will check later). I am really happy with that, it is simple and helps a lot.Template literals are a new feature in ES6 that provide us string template things!Let's have a look on real examplevar a = "Apples"; var b = 10; console.log(`I would like to buy ${b+b} ${a}.`); // I would like to buy 20 Apples.
6
Actions in Play Framework 2.5
Thu, Dec 22nd 2016 3:13p   Dmytro Pastovenskyi
Action - what is that?Requests that comes to application based on Play usually is processed by things which is called action. Action it is just a method that processes parameters of requests and sends result back to web client Example package controllers; import play.mvc.*; /** * This controller contains an action to handle HTTP requests * to the application's home page. */ public class HomeController extends Controller { /** * An action that renders an HTML page with a welcome messag
9
Hello World on Play Framework 2.5 on OSX
Wed, Dec 21st 2016 11:06a   Dmytro Pastovenskyi
Today we are going to make Hello World project based on Play Framework 2.5 on OS XI'm getting back to Play Framework again and I'm going to build simple start project.1. Checking if Java is installedMake sure you have java installed.java -versionIf java is installed you will see message like that:java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode) 2. Installing Typesafe activator (current version is 1.3.
5
Programming Pascal's triangle
Thu, Dec 8th 2016 12:58p   Dmytro Pastovenskyi
What is Pascal's triangle?It is a triangular array which is consists from binomial coefficients (you can see visual representation of it below). To get more information check article on wiki: Pascal's triangle. I had a task where I needed to find out a value in a cell and what I only had were coordinates of it. I came with quit simple solution (Scala) which I really like. The idea is to move up from the initial cell to the borders (left and right, since I know the values there) and once I am




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition