Index: src/backend/utils/adt/pg_locale.c
===================================================================
--- src/backend/utils/adt/pg_locale.c	(HEAD)
+++ src/backend/utils/adt/pg_locale.c	(strftime_win32)
@@ -54,6 +54,7 @@
 #include "utils/memutils.h"
 #include "utils/pg_locale.h"
 
+#include "mb/pg_wchar.h"
 
 #define		MAX_L10N_DATA		80
 
@@ -452,7 +453,53 @@
 	return &CurrentLocaleConv;
 }
 
+#ifdef WIN32
+/*
+ * result is obtained by locale setup of LC_TIME in the environment 
+ * of windows at present CP_ACP. Therefore, conversion is needed
+ * for SERVER_ENCODING. SJIS which is not especially made to server 
+ * encoding in Japan returns. 
+ */
+static size_t
+strftime_win32(char *dst, size_t dstlen, const char *format, const struct tm *tm)
+{
+	size_t	len;
+	wchar_t	wbuf[MAX_L10N_DATA];
+	int		encoding;
 
+	len = strftime(dst, dstlen, format, tm);
+	encoding = GetDatabaseEncoding();
+	if (encoding == PG_SQL_ASCII)
+		return len;
+
+	len = MultiByteToWideChar(CP_ACP, 0, dst, len, wbuf, MAX_L10N_DATA);
+	if (len == 0)
+		ereport(ERROR,
+			(errmsg("could not convert string to wide character:error %lu", GetLastError())));
+	len = WideCharToMultiByte(CP_UTF8, 0, wbuf, len, dst, dstlen, NULL, NULL);
+	if (len == 0)
+		ereport(ERROR,
+			(errmsg("could not convert wide character to UTF-8:error %lu", GetLastError())));
+
+	if (encoding == PG_UTF8)
+		dst[len] = '\0';
+	else
+	{
+		char *convstr = pg_do_encoding_conversion(dst, len, PG_UTF8, encoding);
+		if (convstr == NULL)
+			elog(ERROR, "encoding conversion failed");
+		StrNCpy(dst, convstr, dstlen);
+		len = strlen(dst);
+	}
+
+	return len;
+}
+
+#define strftime(a,b,c,d) strftime_win32(a,b,c,d)
+
+#endif /* WIN32 */
+
+
 /*
  * Update the lc_time localization cache variables if needed.
  */
