We investigate the melting and formation of ice in partially filled hydrophilic and hydrophobic nanopores of 3 nm diameter using molecular dynamics simulations with the mW water model. Above the melting temperature, the partially filled nanopores contain two water phases in coexistence: a condensed liquid plug and a surface-adsorbed phase. It has been long debated in the literature whether the surface-adsorbed phase is involved in the crystallization. We find that only the liquid plug crystallizes on cooling, producing ice I with stacks of hexagonal and cubic layers. The confined ice is wetted by a premelted liquid layer that persists in equilibrium with ice down to temperatures well below its melting point. The liquid-ice transition is first-order-like but rounded. We determine the temperature and enthalpy of melting as a function of the filling fraction of the pore. In agreement with experiments, we find that the melting temperature of the nanoconfined ice is strongly depressed with respect to the bulk Tm, it depends weakly on the filling fraction and is insensitive to the hydrophobicity of the pore wall. The state of water in the crystallized hydrophilic and hydrophobic pores, however, is not the same: the hydrophobic pore has a negligible density of the surface-adsorbed phase and higher fraction of water in the ice phase than the hydrophilic pore. The widths of the ice cores are nevertheless comparable for the hydrophobic and hydrophilic pores, and this may explain their almost identical melting temperatures. The enthalpy of melting ΔHm, when normalized by the actual amount of ice in the pore, is indistinguishable for the hydrophobic and hydrophilic pores, insensitive to the filling fraction, and within the error bars, the same as the difference in enthalpy between bulk liquid and bulk ice evaluated at the temperature of melting of ice in the nanopores.